mirror of
https://codeberg.org/valpackett/tiddlypwa.git
synced 2025-12-06 10:41:03 -08:00
Plugin: batch all addTiddler calls synchronously on initialRead
This fixes opening performance.
This commit is contained in:
parent
728ec0c70e
commit
2c8faed00d
1 changed files with 21 additions and 15 deletions
|
|
@ -408,8 +408,9 @@ Formatted with `deno fmt`.
|
||||||
toDecrypt.push({ thash, ct, iv, hasSepBody: !!(sbct && sbiv), deleted });
|
toDecrypt.push({ thash, ct, iv, hasSepBody: !!(sbct && sbiv), deleted });
|
||||||
}
|
}
|
||||||
this.logger.log('Titles to read: ', toDecrypt.length);
|
this.logger.log('Titles to read: ', toDecrypt.length);
|
||||||
console.time('initialRead');
|
console.time('initial decrypt');
|
||||||
let cur = 0;
|
let cur = 0;
|
||||||
|
const toAdd = [];
|
||||||
for (const { thash, ct, iv, hasSepBody, deleted } of toDecrypt) {
|
for (const { thash, ct, iv, hasSepBody, deleted } of toDecrypt) {
|
||||||
try {
|
try {
|
||||||
if (deleted) continue;
|
if (deleted) continue;
|
||||||
|
|
@ -427,8 +428,19 @@ Formatted with `deno fmt`.
|
||||||
);
|
);
|
||||||
} else tid._is_skinny = true; // Lazy-load separate body
|
} else tid._is_skinny = true; // Lazy-load separate body
|
||||||
}
|
}
|
||||||
// Carefully prevent syncer from re-saving everything we add, and prevent unlocking before the read is actually done
|
toAdd.push(tid);
|
||||||
// TODO: try to optimize by batching all the changes
|
if (cur % 100 == 0) modal.setFeedback(`<p>Decrypting tiddlers… (${cur}/${toDecrypt.length})</p>`);
|
||||||
|
cur += 1;
|
||||||
|
} catch (e) {
|
||||||
|
this.logger.log('Title decryption failed for:', await b64enc(thash));
|
||||||
|
console.error(e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.timeEnd('initial decrypt');
|
||||||
|
console.time('initial add');
|
||||||
|
modal.setFeedback(`<p>Loading tiddlers…</p>`);
|
||||||
|
// Waiting for one change event prevents unlocking before the adding is actually done
|
||||||
const themHandlers = new Promise((resolve) => {
|
const themHandlers = new Promise((resolve) => {
|
||||||
const wiki = this.wiki;
|
const wiki = this.wiki;
|
||||||
// This relies on the sequential ordering of handlers inside the event implementation
|
// This relies on the sequential ordering of handlers inside the event implementation
|
||||||
|
|
@ -437,17 +449,11 @@ Formatted with `deno fmt`.
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
$tw.syncer.storeTiddler(tid); // basically addTiddler but store info to prevent syncer from creating save tasks later
|
// Adds are batched all together SYNCHRONOUSLY to prevent event handlers from running on every add!
|
||||||
|
// storeTiddler is basically addTiddler but store info to prevent syncer from creating save tasks later
|
||||||
|
for (const tid of toAdd) $tw.syncer.storeTiddler(tid);
|
||||||
await themHandlers; // ha
|
await themHandlers; // ha
|
||||||
if (cur % 10 == 0) modal.setFeedback(`<p>Loading tiddlers (${cur}/${toDecrypt.length})</p>`);
|
console.timeEnd('initial add');
|
||||||
cur += 1;
|
|
||||||
} catch (e) {
|
|
||||||
this.logger.log('Title decryption failed for:', await b64enc(thash));
|
|
||||||
console.error(e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
console.timeEnd('initialRead');
|
|
||||||
this.ready = true;
|
this.ready = true;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue