diff --git a/package.json b/package.json index 82959c0d7..6157b23a5 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,7 @@ "jsdoc": "3.6.6", "lorem-ipsum": "2.0.3", "rcedit": "3.0.0", - "webpack": "5.10.1", + "webpack": "5.10.3", "webpack-cli": "4.2.0" }, "optionalDependencies": { diff --git a/src/entities/note.js b/src/entities/note.js index 40dec0137..5100c1e5a 100644 --- a/src/entities/note.js +++ b/src/entities/note.js @@ -21,7 +21,6 @@ const RELATION = 'relation'; * @property {boolean} isProtected - true if note is protected * @property {boolean} isDeleted - true if note is deleted * @property {string|null} deleteId - ID identifying delete transaction - * @property {boolean} isErased - true if note's content is erased after it has been deleted * @property {string} dateCreated - local date time (with offset) * @property {string} dateModified - local date time (with offset) * @property {string} utcDateCreated @@ -70,9 +69,9 @@ class Note extends Entity { /** @returns {*} */ getContent(silentNotFoundError = false) { if (this.content === undefined) { - const content = sql.getValue(`SELECT content FROM note_contents WHERE noteId = ?`, [this.noteId]); + const row = sql.getRow(`SELECT content FROM note_contents WHERE noteId = ?`, [this.noteId]); - if (!content) { + if (!row) { if (silentNotFoundError) { return undefined; } @@ -81,7 +80,7 @@ class Note extends Entity { } } - this.content = content; + this.content = row.content; if (this.isProtected) { if (this.isContentAvailable) { @@ -783,7 +782,7 @@ class Note extends Entity { * @returns {NoteRevision[]} */ getRevisions() { - return this.repository.getEntities("SELECT * FROM note_revisions WHERE isErased = 0 AND noteId = ?", [this.noteId]); + return this.repository.getEntities("SELECT * FROM note_revisions WHERE noteId = ?", [this.noteId]); } /** diff --git a/src/entities/note_revision.js b/src/entities/note_revision.js index eee980182..53afce996 100644 --- a/src/entities/note_revision.js +++ b/src/entities/note_revision.js @@ -28,12 +28,11 @@ const entityChangesService = require('../services/entity_changes.js'); class NoteRevision extends Entity { static get entityName() { return "note_revisions"; } static get primaryKeyName() { return "noteRevisionId"; } - static get hashedProperties() { return ["noteRevisionId", "noteId", "title", "isErased", "isProtected", "dateLastEdited", "dateCreated", "utcDateLastEdited", "utcDateCreated", "utcDateModified"]; } + static get hashedProperties() { return ["noteRevisionId", "noteId", "title", "isProtected", "dateLastEdited", "dateCreated", "utcDateLastEdited", "utcDateCreated", "utcDateModified"]; } constructor(row) { super(row); - this.isErased = !!this.isErased; this.isProtected = !!this.isProtected; if (this.isProtected) { diff --git a/src/routes/api/note_revisions.js b/src/routes/api/note_revisions.js index c016768c7..4fab89c79 100644 --- a/src/routes/api/note_revisions.js +++ b/src/routes/api/note_revisions.js @@ -13,8 +13,7 @@ function getNoteRevisions(req) { LENGTH(note_revision_contents.content) AS contentLength FROM note_revisions JOIN note_revision_contents ON note_revisions.noteRevisionId = note_revision_contents.noteRevisionId - WHERE noteId = ? - AND isErased = 0 + WHERE noteId = ? ORDER BY utcDateCreated DESC`, [req.params.noteId]); } @@ -80,33 +79,16 @@ function downloadNoteRevision(req, res) { res.send(noteRevision.getContent()); } -/** - * @param {NoteRevision} noteRevision - */ -function eraseOneNoteRevision(noteRevision) { - noteRevision.isErased = true; - noteRevision.title = null; - noteRevision.save(); - - noteRevision.setContent(null); -} - function eraseAllNoteRevisions(req) { - const noteRevisionsToErase = repository.getEntities( - 'SELECT * FROM note_revisions WHERE isErased = 0 AND noteId = ?', + const noteRevisionIdsToErase = sql.getColumn( + 'SELECT noteRevisionId FROM note_revisions WHERE isErased = 0 AND noteId = ?', [req.params.noteId]); - for (const noteRevision of noteRevisionsToErase) { - eraseOneNoteRevision(noteRevision); - } + noteRevisionService.eraseNoteRevisions(noteRevisionIdsToErase); } function eraseNoteRevision(req) { - const noteRevision = repository.getNoteRevision(req.params.noteRevisionId); - - if (noteRevision && !noteRevision.isErased) { - eraseOneNoteRevision(noteRevision); - } + noteRevisionService.eraseNoteRevisions([req.params.noteRevisionId]); } function restoreNoteRevision(req) { diff --git a/src/routes/api/tree.js b/src/routes/api/tree.js index f371de4e5..b9cb69b35 100644 --- a/src/routes/api/tree.js +++ b/src/routes/api/tree.js @@ -114,6 +114,10 @@ function getTree(req) { const collectedNoteIds = new Set([subTreeNoteId]); function collect(parentNote) { + if (!parentNote) { + console.trace(parentNote); + } + for (const childNote of parentNote.children) { collectedNoteIds.add(childNote.noteId); diff --git a/src/services/note_revisions.js b/src/services/note_revisions.js index d1e7f37b4..60dfa00b5 100644 --- a/src/services/note_revisions.js +++ b/src/services/note_revisions.js @@ -1,8 +1,9 @@ "use strict"; const NoteRevision = require('../entities/note_revision'); -const dateUtils = require('../services/date_utils'); -const log = require('../services/log'); +const dateUtils = require('./date_utils'); +const log = require('./log'); +const sql = require('./sql'); /** * @param {Note} note @@ -69,7 +70,20 @@ function createNoteRevision(note) { return noteRevision; } +function eraseNoteRevisions(noteRevisionIdsToErase) { + if (noteRevisionIdsToErase.length === 0) { + return; + } + + sql.executeMany(`DELETE FROM note_revisions WHERE noteRevisionId IN (???)`, noteRevisionIdsToErase); + sql.executeMany(`UPDATE entity_changes SET isErased = 1 WHERE entityName = 'note_revisions' AND entityId IN (???)`, noteRevisionIdsToErase); + + sql.executeMany(`DELETE FROM note_revision_contents WHERE noteRevisionId IN (???)`, noteRevisionIdsToErase); + sql.executeMany(`UPDATE entity_changes SET isErased = 1 WHERE entityName = 'note_revision_contents' AND entityId IN (???)`, noteRevisionIdsToErase); +} + module.exports = { protectNoteRevisions, - createNoteRevision + createNoteRevision, + eraseNoteRevisions }; diff --git a/src/services/notes.js b/src/services/notes.js index fbc07de8d..c1034726f 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -698,7 +698,7 @@ function eraseNotes(noteIdsToErase) { const noteRevisionIdsToErase = sql.getManyRows(`SELECT noteRevisionId FROM note_revisions WHERE noteId IN (???)`, noteIdsToErase) .map(row => row.noteRevisionId); - eraseNoteRevisions(noteRevisionIdsToErase); + noteRevisionService.eraseNoteRevisions(noteRevisionIdsToErase); log.info(`Erased notes: ${JSON.stringify(noteIdsToErase)}`); } @@ -723,18 +723,6 @@ function eraseAttributes(attributeIdsToErase) { sql.executeMany(`UPDATE entity_changes SET isErased = 1 WHERE entityName = 'attributes' AND entityId IN (???)`, attributeIdsToErase); } -function eraseNoteRevisions(noteRevisionIdsToErase) { - if (noteRevisionIdsToErase.length === 0) { - return; - } - - sql.executeMany(`DELETE FROM note_revisions WHERE noteRevisionId IN (???)`, noteRevisionIdsToErase); - sql.executeMany(`UPDATE entity_changes SET isErased = 1 WHERE entityName = 'note_revisions' AND entityId IN (???)`, noteRevisionIdsToErase); - - sql.executeMany(`DELETE FROM note_revision_contents WHERE noteRevisionId IN (???)`, noteRevisionIdsToErase); - sql.executeMany(`UPDATE entity_changes SET isErased = 1 WHERE entityName = 'note_revision_contents' AND entityId IN (???)`, noteRevisionIdsToErase); -} - function eraseDeletedEntities(eraseEntitiesAfterTimeInSeconds = null) { if (eraseEntitiesAfterTimeInSeconds === null) { eraseEntitiesAfterTimeInSeconds = optionService.getOptionInt('eraseEntitiesAfterTimeInSeconds');