Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/routes/api/revisions.js
#	src/services/bulk_actions.js
  • Loading branch information
zadam committed Dec 11, 2023
2 parents c35167f + 0ac397e commit df85a5e
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 33 deletions.
19 changes: 10 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "trilium",
"productName": "Trilium Notes",
"description": "Trilium Notes",
"version": "0.62.2",
"version": "0.62.4",
"license": "AGPL-3.0-only",
"main": "electron.js",
"bin": {
Expand Down Expand Up @@ -112,7 +112,7 @@
},
"devDependencies": {
"cross-env": "7.0.3",
"electron": "25.9.5",
"electron": "25.9.8",
"electron-builder": "24.6.4",
"electron-packager": "17.1.2",
"electron-rebuild": "3.2.9",
Expand Down
5 changes: 3 additions & 2 deletions src/routes/api/revisions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const cls = require('../../services/cls.js');
const path = require('path');
const becca = require('../../becca/becca.js');
const blobService = require('../../services/blob.js');
const eraseService = require("../../services/erase.js");

function getRevisionBlob(req) {
const preview = req.query.preview === 'true';
Expand Down Expand Up @@ -88,11 +89,11 @@ function eraseAllRevisions(req) {
const revisionIdsToErase = sql.getColumn('SELECT revisionId FROM revisions WHERE noteId = ?',
[req.params.noteId]);

revisionService.eraseRevisions(revisionIdsToErase);
eraseService.eraseRevisions(revisionIdsToErase);
}

function eraseRevision(req) {
revisionService.eraseRevisions([req.params.revisionId]);
eraseService.eraseRevisions([req.params.revisionId]);
}

function restoreRevision(req) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/build.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = { buildDate:"2023-11-21T20:49:24+01:00", buildRevision: "e2b1421bf3d764ffe444a103c118e67d8c563673" };
module.exports = { buildDate:"2023-12-07T00:03:59+01:00", buildRevision: "2e23c521c356c2305124f5df0f474532fa5f34ce" };
3 changes: 2 additions & 1 deletion src/services/bulk_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const becca = require('../becca/becca.js');
const cloningService = require('./cloning.js');
const branchService = require('./branches.js');
const utils = require('./utils.js');
const eraseService = require("./erase.js");

const ACTION_HANDLERS = {
addLabel: (action, note) => {
Expand All @@ -18,7 +19,7 @@ const ACTION_HANDLERS = {
note.deleteNote(deleteId);
},
deleteRevisions: (action, note) => {
revisionService.eraseRevisions(note.getRevisions().map(rev => rev.revisionId));
eraseService.eraseRevisions(note.getRevisions().map(rev => rev.revisionId));
},
deleteLabel: (action, note) => {
for (const label of note.getOwnedLabels(action.labelName)) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/consistency_checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ class ConsistencyChecks {
WHERE blobs.blobId IS NULL`,
({revisionId, blobId}) => {
if (this.autoFix) {
revisionService.eraseRevisions([revisionId]);
eraseService.eraseRevisions([revisionId]);

this.reloadNeeded = true;

Expand Down
17 changes: 15 additions & 2 deletions src/services/erase.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function eraseNotes(noteIdsToErase) {
const revisionIdsToErase = sql.getManyRows(`SELECT revisionId FROM revisions WHERE noteId IN (???)`, noteIdsToErase)
.map(row => row.revisionId);

revisionService.eraseRevisions(revisionIdsToErase);
eraseRevisions(revisionIdsToErase);

log.info(`Erased notes: ${JSON.stringify(noteIdsToErase)}`);
}
Expand Down Expand Up @@ -79,6 +79,18 @@ function eraseAttachments(attachmentIdsToErase) {
log.info(`Erased attachments: ${JSON.stringify(attachmentIdsToErase)}`);
}

function eraseRevisions(revisionIdsToErase) {
if (revisionIdsToErase.length === 0) {
return;
}

sql.executeMany(`DELETE FROM revisions WHERE revisionId IN (???)`, revisionIdsToErase);

setEntityChangesAsErased(sql.getManyRows(`SELECT * FROM entity_changes WHERE entityName = 'revisions' AND entityId IN (???)`, revisionIdsToErase));

log.info(`Removed revisions: ${JSON.stringify(revisionIdsToErase)}`);
}

function eraseUnusedBlobs() {
const unusedBlobIds = sql.getColumn(`
SELECT blobs.blobId
Expand Down Expand Up @@ -184,5 +196,6 @@ module.exports = {
eraseUnusedAttachmentsNow,
eraseNotesWithDeleteId,
eraseUnusedBlobs,
eraseAttachments
eraseAttachments,
eraseRevisions
};
14 changes: 1 addition & 13 deletions src/services/revisions.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,6 @@ function protectRevisions(note) {
}
}

function eraseRevisions(revisionIdsToErase) {
if (revisionIdsToErase.length === 0) {
return;
}

log.info(`Removing revisions: ${JSON.stringify(revisionIdsToErase)}`);

sql.executeMany(`DELETE FROM revisions WHERE revisionId IN (???)`, revisionIdsToErase);
sql.executeMany(`UPDATE entity_changes SET isErased = 1, utcDateChanged = '${dateUtils.utcNowDateTime()}' WHERE entityName = 'revisions' AND entityId IN (???)`, revisionIdsToErase);
}

module.exports = {
protectRevisions,
eraseRevisions
protectRevisions
};
5 changes: 3 additions & 2 deletions src/services/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,9 @@ function sortNotesIfNeeded(parentNoteId) {
function setNoteToParent(noteId, prefix, parentNoteId) {
const parentNote = becca.getNote(parentNoteId);

if (!parentNote) {
throw new Error(`Cannot move note to deleted parent note '${parentNoteId}'`);
if (parentNoteId && !parentNote) {
// null parentNoteId is a valid value
throw new Error(`Cannot move note to deleted / missing parent note '${parentNoteId}'`);
}

// case where there might be more such branches is ignored. It's expected there should be just one
Expand Down
2 changes: 2 additions & 0 deletions src/services/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ function isElectron() {
}

function hash(text) {
text = text.normalize();

return crypto.createHash('sha1').update(text).digest('base64');
}

Expand Down

0 comments on commit df85a5e

Please sign in to comment.