summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Wu2018-03-10 16:51:00 +0800
committerMax Wu2018-03-10 16:51:00 +0800
commit16cb842b946d55668318c08cf2e0aed001b9f855 (patch)
treeff8da1e0826b539514c1e3323bc211d8707fd38d
parentd08c9522c0dd414a6fed1671064701160d233603 (diff)
Improve history migration performance
Signed-off-by: Max Wu <jackymaxj@gmail.com>
Diffstat (limited to '')
-rw-r--r--lib/history.js16
1 files changed, 5 insertions, 11 deletions
diff --git a/lib/history.js b/lib/history.js
index f3d4440e..c7d2472c 100644
--- a/lib/history.js
+++ b/lib/history.js
@@ -31,20 +31,14 @@ function getHistory (userid, callback) {
history = JSON.parse(user.history)
// migrate LZString encoded note id to base64url encoded note id
for (let i = 0, l = history.length; i < l; i++) {
- let item = history[i]
- // try to parse in base64url
- let id = models.Note.decodeNoteId(item.id)
- if (!id || !models.Note.checkNoteIdValid(id)) {
- // try to parse in LZString if it can't be parsed in base64url
- try {
- id = LZString.decompressFromBase64(item.id)
- } catch (err) {
- id = null
- }
+ try {
+ let id = LZString.decompressFromBase64(history[i].id)
if (id && models.Note.checkNoteIdValid(id)) {
- // replace the note id to base64url encoded note id
history[i].id = models.Note.encodeNoteId(id)
}
+ } catch (err) {
+ // most error here comes from LZString, ignore
+ logger.error(err)
}
}
history = parseHistoryToObject(history)