mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 09:58:32 +02:00
repository has now first level cache
This commit is contained in:
parent
081693f263
commit
5c0355718f
@ -50,7 +50,7 @@
|
||||
"imagemin-pngquant": "8.0.0",
|
||||
"ini": "1.3.5",
|
||||
"is-svg": "4.2.1",
|
||||
"jimp": "0.10.0",
|
||||
"jimp": "0.10.1",
|
||||
"mime-types": "2.1.26",
|
||||
"multer": "1.4.2",
|
||||
"node-abi": "2.15.0",
|
||||
@ -77,7 +77,7 @@
|
||||
"yazl": "^2.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"electron": "9.0.0-beta.13",
|
||||
"electron": "9.0.0-beta.14",
|
||||
"electron-builder": "22.4.1",
|
||||
"electron-packager": "14.2.1",
|
||||
"electron-rebuild": "1.10.1",
|
||||
|
@ -45,11 +45,7 @@ class Attribute extends Entity {
|
||||
* @returns {Promise<Note|null>}
|
||||
*/
|
||||
async getNote() {
|
||||
if (!this.__note) {
|
||||
this.__note = await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]);
|
||||
}
|
||||
|
||||
return this.__note;
|
||||
return await repository.getNote(this.noteId);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,11 +60,7 @@ class Attribute extends Entity {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!this.__targetNote) {
|
||||
this.__targetNote = await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.value]);
|
||||
}
|
||||
|
||||
return this.__targetNote;
|
||||
return await repository.getNote(this.value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,9 +28,14 @@ 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", "deleteId", "prefix"]; }
|
||||
|
||||
/** @returns {Note|null} */
|
||||
/** @returns {Promise<Note|null>} */
|
||||
async getNote() {
|
||||
return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]);
|
||||
return await repository.getNote(this.noteId);
|
||||
}
|
||||
|
||||
/** @returns {Promise<Note|null>} */
|
||||
async getParentNote() {
|
||||
return await repository.getNote(this.parentNoteId);
|
||||
}
|
||||
|
||||
async beforeSaving() {
|
||||
|
@ -48,7 +48,7 @@ class NoteRevision extends Entity {
|
||||
}
|
||||
|
||||
async getNote() {
|
||||
return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]);
|
||||
return await repository.getNote(this.noteId);
|
||||
}
|
||||
|
||||
/** @returns {boolean} true if the note has string content (not binary) */
|
||||
|
@ -37,6 +37,14 @@ function reset() {
|
||||
clsHooked.reset();
|
||||
}
|
||||
|
||||
function getEntityFromCache(entityName, entityId) {
|
||||
return namespace.get(entityName + '-' + entityId);
|
||||
}
|
||||
|
||||
function setEntityToCache(entityName, entityId, entity) {
|
||||
return namespace.set(entityName + '-' + entityId, entity);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init,
|
||||
wrap,
|
||||
@ -46,5 +54,7 @@ module.exports = {
|
||||
isEntityEventsDisabled,
|
||||
reset,
|
||||
getSyncRows,
|
||||
addSyncRow
|
||||
addSyncRow,
|
||||
getEntityFromCache,
|
||||
setEntityToCache
|
||||
};
|
@ -544,16 +544,22 @@ async function deleteBranch(branch, deleteId, taskContext) {
|
||||
note.deleteId = deleteId;
|
||||
await note.save();
|
||||
|
||||
console.log("Deleting note", note.noteId);
|
||||
|
||||
for (const attribute of await note.getOwnedAttributes()) {
|
||||
attribute.isDeleted = true;
|
||||
attribute.deleteId = deleteId;
|
||||
await attribute.save();
|
||||
|
||||
console.log("Deleting note's", note.noteId, "attribute", attribute.attributeId);
|
||||
}
|
||||
|
||||
for (const relation of await note.getTargetRelations()) {
|
||||
relation.isDeleted = true;
|
||||
relation.deleteId = deleteId;
|
||||
await relation.save();
|
||||
|
||||
console.log("Deleting note's", note.noteId, "target relation", relation.attributeId);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -37,9 +37,21 @@ async function getEntity(query, params = []) {
|
||||
return entityConstructor.createEntityFromRow(row);
|
||||
}
|
||||
|
||||
async function getCachedEntity(entityName, entityId, query) {
|
||||
let entity = cls.getEntityFromCache(entityName, entityId);
|
||||
|
||||
if (!entity) {
|
||||
entity = await getEntity(query, [entityId]);
|
||||
|
||||
cls.setEntityToCache(entityName, entityId, entity);
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
/** @returns {Promise<Note|null>} */
|
||||
async function getNote(noteId) {
|
||||
return await getEntity("SELECT * FROM notes WHERE noteId = ?", [noteId]);
|
||||
return await getCachedEntity('notes', noteId, "SELECT * FROM notes WHERE noteId = ?");
|
||||
}
|
||||
|
||||
/** @returns {Promise<Note[]>} */
|
||||
@ -59,17 +71,17 @@ async function getNotes(noteIds) {
|
||||
|
||||
/** @returns {Promise<NoteRevision|null>} */
|
||||
async function getNoteRevision(noteRevisionId) {
|
||||
return await getEntity("SELECT * FROM note_revisions WHERE noteRevisionId = ?", [noteRevisionId]);
|
||||
return await getCachedEntity('note_revisions', noteRevisionId, "SELECT * FROM note_revisions WHERE noteRevisionId = ?");
|
||||
}
|
||||
|
||||
/** @returns {Promise<Branch|null>} */
|
||||
async function getBranch(branchId) {
|
||||
return await getEntity("SELECT * FROM branches WHERE branchId = ?", [branchId]);
|
||||
return await getCachedEntity('branches', branchId, "SELECT * FROM branches WHERE branchId = ?", [branchId]);
|
||||
}
|
||||
|
||||
/** @returns {Promise<Attribute|null>} */
|
||||
async function getAttribute(attributeId) {
|
||||
return await getEntity("SELECT * FROM attributes WHERE attributeId = ?", [attributeId]);
|
||||
return await getCachedEntity('attributes', attributeId, "SELECT * FROM attributes WHERE attributeId = ?");
|
||||
}
|
||||
|
||||
/** @returns {Promise<Option|null>} */
|
||||
|
Loading…
x
Reference in New Issue
Block a user