Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
  • Loading branch information
zadam committed Nov 6, 2023
2 parents 809ffa0 + 7fc1eb5 commit f8bc03f
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 10 deletions.
4 changes: 4 additions & 0 deletions db/migrations/0220__migrate_images_to_attachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ module.exports = () => {
const becca = require("../../src/becca/becca");
const cls = require("../../src/services/cls");
const log = require("../../src/services/log");
const sql = require("../../src/services/sql");

cls.init(() => {
// emergency disabling of image compression since it appears to make problems in migration to 0.61
sql.execute(`UPDATE options SET value = 'false' WHERE name = 'compressImages'`);

beccaLoader.load();

for (const note of Object.values(becca.notes)) {
Expand Down
2 changes: 2 additions & 0 deletions db/migrations/0227__disable_image_compression.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- emergency disabling of image compression since it appears to make problems in migration to 0.61
UPDATE options SET value = 'false' WHERE name = 'compressImages';
2 changes: 1 addition & 1 deletion 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.61.11",
"version": "0.61.13",
"license": "AGPL-3.0-only",
"main": "electron.js",
"bin": {
Expand Down
2 changes: 1 addition & 1 deletion src/public/app/services/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ if (utils.isElectron()) {
await reportError(arg.method, arg.url, arg.statusCode, arg.body);
}

idToRequestMap[arg.requestId].reject();
idToRequestMap[arg.requestId].reject(new Error(`Server responded with ${arg.statusCode}`));
}

delete idToRequestMap[arg.requestId];
Expand Down
2 changes: 1 addition & 1 deletion src/services/app_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const build = require('./build');
const packageJson = require('../../package');
const {TRILIUM_DATA_DIR} = require('./data_dir');

const APP_DB_VERSION = 226;
const APP_DB_VERSION = 227;
const SYNC_VERSION = 31;
const CLIPPER_PROTOCOL_VERSION = "1.0";

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-03T11:46:53+01:00", buildRevision: "01093d05d7ca1ede0c9af3fe2f5b04969ade816d" };
module.exports = { buildDate:"2023-11-06T00:21:41+01:00", buildRevision: "531e9d4aff47b7e8332420645546d25ab28acf85" };
12 changes: 10 additions & 2 deletions src/services/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,16 @@ function saveImageToAttachment(noteId, uploadBuffer, originalName, shrinkImageSw
title: fileName
});

const noteService = require("../services/notes");
noteService.asyncPostProcessContent(note, note.getContent()); // to mark an unused attachment for deletion
// TODO: this is a quick-fix solution of a recursive bug - this is called from asyncPostProcessContent()
// find some async way to do this - perhaps some global timeout with a Set of noteIds needing one more
// run of asyncPostProcessContent
setTimeout(() => {
sql.transactional(() => {
const note = becca.getNoteOrThrow(noteId);
const noteService = require("../services/notes");
noteService.asyncPostProcessContent(note, note.getContent()); // to mark an unused attachment for deletion
});
}, 5000);

// resizing images asynchronously since JIMP does not support sync operation
processImage(uploadBuffer, originalName, shrinkImageSwitch).then(({buffer, imageFormat}) => {
Expand Down
14 changes: 10 additions & 4 deletions src/services/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,21 +292,24 @@ async function syncRequest(syncContext, method, requestPath, body) {
return response;
}

function getEntityChangeRow(entityName, entityId) {
function getEntityChangeRow(entityChange) {
const {entityName, entityId} = entityChange;

if (entityName === 'note_reordering') {
return sql.getMap("SELECT branchId, notePosition FROM branches WHERE parentNoteId = ? AND isDeleted = 0", [entityId]);
}
else {
const primaryKey = entityConstructor.getEntityFromEntityName(entityName).primaryKeyName;

if (!primaryKey) {
throw new Error(`Unknown entity '${entityName}'`);
throw new Error(`Unknown entity for entity change ${JSON.stringify(entityChange)}`);
}

const entityRow = sql.getRow(`SELECT * FROM ${entityName} WHERE ${primaryKey} = ?`, [entityId]);

if (!entityRow) {
throw new Error(`Entity ${entityName} '${entityId}' not found.`);
log.error(`Cannot find entity for entity change ${JSON.stringify(entityChange)}`);
return null;
}

if (entityName === 'blobs' && entityRow.content !== null) {
Expand All @@ -332,7 +335,10 @@ function getEntityChangeRecords(entityChanges) {
continue;
}

const entity = getEntityChangeRow(entityChange.entityName, entityChange.entityId);
const entity = getEntityChangeRow(entityChange);
if (!entity) {
continue;
}

const record = { entityChange, entity };

Expand Down

0 comments on commit f8bc03f

Please sign in to comment.