mirror of
https://github.com/zadam/trilium.git
synced 2025-06-05 01:18:44 +02:00
fix problems with updating note in note cache when entities are coming out of order (e.g. sync)
This commit is contained in:
parent
918e827d91
commit
0bd9b849b2
12
package-lock.json
generated
12
package-lock.json
generated
@ -2801,9 +2801,9 @@
|
||||
}
|
||||
},
|
||||
"dayjs": {
|
||||
"version": "1.8.34",
|
||||
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.8.34.tgz",
|
||||
"integrity": "sha512-Olb+E6EoMvdPmAMq2QoucuyZycKHjTlBXmRx8Ada+wGtq4SIXuDCdtoaX4KkK0yjf1fJLnwXQURr8gQKWKaybw=="
|
||||
"version": "1.8.35",
|
||||
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.8.35.tgz",
|
||||
"integrity": "sha512-isAbIEenO4ilm6f8cpqvgjZCsuerDAz2Kb7ri201AiNn58aqXuaLJEnCtfIMdCvERZHNGRY5lDMTr/jdAnKSWQ=="
|
||||
},
|
||||
"debug": {
|
||||
"version": "4.1.1",
|
||||
@ -3104,9 +3104,9 @@
|
||||
}
|
||||
},
|
||||
"electron": {
|
||||
"version": "9.2.1",
|
||||
"resolved": "https://registry.npmjs.org/electron/-/electron-9.2.1.tgz",
|
||||
"integrity": "sha512-ZsetaQjXB8+9/EFW1FnfK4ukpkwXCxMEaiKiUZhZ0ZLFlLnFCpe0Bg4vdDf7e4boWGcnlgN1jAJpBw7w0eXuqA==",
|
||||
"version": "9.3.0",
|
||||
"resolved": "https://registry.npmjs.org/electron/-/electron-9.3.0.tgz",
|
||||
"integrity": "sha512-7zPLEZ+kOjVJqfawMQ0vVuZZRqvZIeiID3tbjjbVybbxXIlFMpZ2jogoh7PV3rLrtm+dKRfu7Qc4E7ob1d0FqQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@electron/get": "^1.0.1",
|
||||
|
@ -32,7 +32,7 @@
|
||||
"commonmark": "0.29.1",
|
||||
"cookie-parser": "1.4.5",
|
||||
"csurf": "1.11.0",
|
||||
"dayjs": "1.8.34",
|
||||
"dayjs": "1.8.35",
|
||||
"debug": "4.1.1",
|
||||
"ejs": "3.1.5",
|
||||
"electron-debug": "3.1.0",
|
||||
|
@ -6,6 +6,33 @@ class Note {
|
||||
constructor(noteCache, row) {
|
||||
/** @param {NoteCache} */
|
||||
this.noteCache = noteCache;
|
||||
|
||||
this.update(row);
|
||||
|
||||
/** @param {Branch[]} */
|
||||
this.parentBranches = [];
|
||||
/** @param {Note[]} */
|
||||
this.parents = [];
|
||||
/** @param {Note[]} */
|
||||
this.children = [];
|
||||
/** @param {Attribute[]} */
|
||||
this.ownedAttributes = [];
|
||||
|
||||
/** @param {Attribute[]|null} */
|
||||
this.attributeCache = null;
|
||||
/** @param {Attribute[]|null} */
|
||||
this.inheritableAttributeCache = null;
|
||||
|
||||
/** @param {Attribute[]} */
|
||||
this.targetRelations = [];
|
||||
|
||||
this.noteCache.notes[this.noteId] = this;
|
||||
|
||||
/** @param {Note[]|null} */
|
||||
this.ancestorCache = null;
|
||||
}
|
||||
|
||||
update(row) {
|
||||
/** @param {string} */
|
||||
this.noteId = row.noteId;
|
||||
/** @param {string} */
|
||||
@ -26,34 +53,11 @@ class Note {
|
||||
this.isProtected = !!row.isProtected;
|
||||
/** @param {boolean} */
|
||||
this.isDecrypted = !row.isProtected || !!row.isContentAvailable;
|
||||
/** @param {Branch[]} */
|
||||
this.parentBranches = [];
|
||||
/** @param {Note[]} */
|
||||
this.parents = [];
|
||||
/** @param {Note[]} */
|
||||
this.children = [];
|
||||
/** @param {Attribute[]} */
|
||||
this.ownedAttributes = [];
|
||||
|
||||
/** @param {Attribute[]|null} */
|
||||
this.attributeCache = null;
|
||||
/** @param {Attribute[]|null} */
|
||||
this.inheritableAttributeCache = null;
|
||||
|
||||
/** @param {Attribute[]} */
|
||||
this.targetRelations = [];
|
||||
this.decrypt();
|
||||
|
||||
/** @param {string|null} */
|
||||
this.flatTextCache = null;
|
||||
|
||||
this.noteCache.notes[this.noteId] = this;
|
||||
|
||||
if (protectedSessionService.isProtectedSessionAvailable()) {
|
||||
this.decrypt();
|
||||
}
|
||||
|
||||
/** @param {Note[]|null} */
|
||||
this.ancestorCache = null;
|
||||
}
|
||||
|
||||
/** @return {Attribute[]} */
|
||||
|
@ -31,7 +31,7 @@ function load() {
|
||||
}
|
||||
|
||||
eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED, eventService.ENTITY_SYNCED], ({entityName, entity}) => {
|
||||
// note that entity can also be just POJO without methods if coming FROM entity_changes
|
||||
// note that entity can also be just POJO without methods if coming from sync
|
||||
|
||||
if (!noteCache.loaded) {
|
||||
return;
|
||||
@ -44,15 +44,7 @@ eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED
|
||||
delete noteCache.notes[noteId];
|
||||
}
|
||||
else if (noteId in noteCache.notes) {
|
||||
const note = noteCache.notes[noteId];
|
||||
|
||||
// we can assume we have protected session since we managed to update
|
||||
note.title = entity.title;
|
||||
note.isProtected = entity.isProtected;
|
||||
note.isDecrypted = !entity.isProtected || !!entity.isContentAvailable;
|
||||
note.flatTextCache = null;
|
||||
|
||||
note.decrypt();
|
||||
noteCache.notes[noteId].update(entity);
|
||||
}
|
||||
else {
|
||||
const note = new Note(noteCache, entity);
|
||||
|
@ -84,9 +84,7 @@ class NoteCacheFlatTextExp extends Expression {
|
||||
const foundAttrTokens = [];
|
||||
|
||||
for (const token of this.tokens) {
|
||||
// not clear why, but sometimes note.type or note.mime is undefined
|
||||
if ((note.type && note.type.includes(token))
|
||||
|| (note.mime && note.mime.includes(token))) {
|
||||
if (note.type.includes(token) || note.mime.includes(token)) {
|
||||
foundAttrTokens.push(token);
|
||||
}
|
||||
|
||||
|
@ -37,11 +37,11 @@ async function sync() {
|
||||
do {
|
||||
const syncContext = await login();
|
||||
|
||||
await pushSync(syncContext);
|
||||
await pushChanges(syncContext);
|
||||
|
||||
await pullSync(syncContext);
|
||||
await pullChanges(syncContext);
|
||||
|
||||
await pushSync(syncContext);
|
||||
await pushChanges(syncContext);
|
||||
|
||||
await syncFinished(syncContext);
|
||||
|
||||
@ -122,7 +122,7 @@ async function doLogin() {
|
||||
return syncContext;
|
||||
}
|
||||
|
||||
async function pullSync(syncContext) {
|
||||
async function pullChanges(syncContext) {
|
||||
let atLeastOnePullApplied = false;
|
||||
|
||||
while (true) {
|
||||
@ -175,7 +175,7 @@ async function pullSync(syncContext) {
|
||||
log.info("Finished pull");
|
||||
}
|
||||
|
||||
async function pushSync(syncContext) {
|
||||
async function pushChanges(syncContext) {
|
||||
let lastSyncedPush = getLastSyncedPush();
|
||||
|
||||
while (true) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user