mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 09:58:32 +02:00
fix note move to different parent in note cache
This commit is contained in:
parent
fdc3a7a7f2
commit
c55bc471db
@ -27,6 +27,13 @@ class Branch extends Entity {
|
||||
// notePosition is not part of hash because it would produce a lot of updates in case of reordering
|
||||
static get hashedProperties() { return ["branchId", "noteId", "parentNoteId", "isDeleted", "prefix"]; }
|
||||
|
||||
constructor(row = {}) {
|
||||
super(row);
|
||||
|
||||
// used to detect move in note tree
|
||||
this.origParentNoteId = this.parentNoteId;
|
||||
}
|
||||
|
||||
async getNote() {
|
||||
return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]);
|
||||
}
|
||||
|
@ -260,20 +260,19 @@ eventService.subscribe(eventService.ENTITY_CHANGED, async ({entityName, entity})
|
||||
else if (entityName === 'branches') {
|
||||
const branch = entity;
|
||||
|
||||
if (childToParent[branch.noteId]) {
|
||||
childToParent[branch.noteId] = childToParent[branch.noteId].filter(noteId => noteId !== branch.parentNoteId)
|
||||
}
|
||||
// first we remove records for original placement (if they exist)
|
||||
childToParent[branch.noteId] = childToParent[branch.noteId] || [];
|
||||
childToParent[branch.noteId] = childToParent[branch.noteId].filter(noteId => noteId !== branch.origParentNoteId);
|
||||
|
||||
if (branch.isDeleted) {
|
||||
delete prefixes[branch.noteId + '-' + branch.parentNoteId];
|
||||
delete childParentToBranchId[branch.noteId + '-' + branch.parentNoteId];
|
||||
}
|
||||
else {
|
||||
delete prefixes[branch.noteId + '-' + branch.origParentNoteId];
|
||||
delete childParentToBranchId[branch.noteId + '-' + branch.origParentNoteId];
|
||||
|
||||
if (!branch.isDeleted) {
|
||||
// ... and then we create new records
|
||||
if (branch.prefix) {
|
||||
prefixes[branch.noteId + '-' + branch.parentNoteId] = branch.prefix;
|
||||
}
|
||||
|
||||
childToParent[branch.noteId] = childToParent[branch.noteId] || [];
|
||||
childToParent[branch.noteId].push(branch.parentNoteId);
|
||||
childParentToBranchId[branch.noteId + '-' + branch.parentNoteId] = branch.branchId;
|
||||
}
|
||||
|
@ -68,9 +68,11 @@ async function updateEntity(entity) {
|
||||
|
||||
const clone = Object.assign({}, entity);
|
||||
|
||||
// transient properties not supposed to be persisted
|
||||
delete clone.jsonContent;
|
||||
delete clone.isOwned;
|
||||
delete clone.isChanged;
|
||||
delete clone.origParentNoteId;
|
||||
delete clone.__attributeCache;
|
||||
|
||||
for (const key in clone) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user