Skip to content

Commit 16cb842

Browse files
committed
Improve history migration performance
Signed-off-by: Max Wu <jackymaxj@gmail.com>
1 parent d08c952 commit 16cb842

1 file changed

Lines changed: 5 additions & 11 deletions

File tree

lib/history.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,14 @@ function getHistory (userid, callback) {
3131
history = JSON.parse(user.history)
3232
// migrate LZString encoded note id to base64url encoded note id
3333
for (let i = 0, l = history.length; i < l; i++) {
34-
let item = history[i]
35-
// try to parse in base64url
36-
let id = models.Note.decodeNoteId(item.id)
37-
if (!id || !models.Note.checkNoteIdValid(id)) {
38-
// try to parse in LZString if it can't be parsed in base64url
39-
try {
40-
id = LZString.decompressFromBase64(item.id)
41-
} catch (err) {
42-
id = null
43-
}
34+
try {
35+
let id = LZString.decompressFromBase64(history[i].id)
4436
if (id && models.Note.checkNoteIdValid(id)) {
45-
// replace the note id to base64url encoded note id
4637
history[i].id = models.Note.encodeNoteId(id)
4738
}
39+
} catch (err) {
40+
// most error here comes from LZString, ignore
41+
logger.error(err)
4842
}
4943
}
5044
history = parseHistoryToObject(history)

0 commit comments

Comments
 (0)