mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-12-23 16:54:04 +00:00
Improve history migration performance
Signed-off-by: Max Wu <jackymaxj@gmail.com>
This commit is contained in:
parent
d08c9522c0
commit
16cb842b94
1 changed files with 5 additions and 11 deletions
|
@ -31,20 +31,14 @@ function getHistory (userid, callback) {
|
||||||
history = JSON.parse(user.history)
|
history = JSON.parse(user.history)
|
||||||
// migrate LZString encoded note id to base64url encoded note id
|
// migrate LZString encoded note id to base64url encoded note id
|
||||||
for (let i = 0, l = history.length; i < l; i++) {
|
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 {
|
try {
|
||||||
id = LZString.decompressFromBase64(item.id)
|
let id = LZString.decompressFromBase64(history[i].id)
|
||||||
} catch (err) {
|
|
||||||
id = null
|
|
||||||
}
|
|
||||||
if (id && models.Note.checkNoteIdValid(id)) {
|
if (id && models.Note.checkNoteIdValid(id)) {
|
||||||
// replace the note id to base64url encoded note id
|
|
||||||
history[i].id = models.Note.encodeNoteId(id)
|
history[i].id = models.Note.encodeNoteId(id)
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
// most error here comes from LZString, ignore
|
||||||
|
logger.error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
history = parseHistoryToObject(history)
|
history = parseHistoryToObject(history)
|
||||||
|
|
Loading…
Reference in a new issue