From 807941e6a50759666f2cd8fc413dc3ad6a9249b8 Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 21 Jan 2024 20:50:38 +0100 Subject: [PATCH] disable scanning for links while migration is running #4535 --- src/services/cls.js | 12 +++++++++++- src/services/migration.js | 4 ++++ src/services/notes.js | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/services/cls.js b/src/services/cls.js index 0bfde4436..8e2c2870c 100644 --- a/src/services/cls.js +++ b/src/services/cls.js @@ -48,6 +48,14 @@ function isEntityEventsDisabled() { return !!namespace.get('disableEntityEvents'); } +function setMigrationRunning(running) { + namespace.set('migrationRunning', !!running); +} + +function isMigrationRunning() { + return !!namespace.get('migrationRunning'); +} + function disableSlowQueryLogging(disable) { namespace.set('disableSlowQueryLogging', disable); } @@ -102,5 +110,7 @@ module.exports = { putEntityChange, ignoreEntityChangeIds, disableSlowQueryLogging, - isSlowQueryLoggingDisabled + isSlowQueryLoggingDisabled, + setMigrationRunning, + isMigrationRunning }; diff --git a/src/services/migration.js b/src/services/migration.js index 58b910d7b..e5ca3dc6c 100644 --- a/src/services/migration.js +++ b/src/services/migration.js @@ -5,6 +5,7 @@ const log = require('./log'); const utils = require('./utils'); const resourceDir = require('./resource_dir'); const appInfo = require('./app_info'); +const cls = require('./cls.js'); async function migrate() { const currentDbVersion = getDbVersion(); @@ -51,6 +52,9 @@ async function migrate() { // all migrations are executed in one transaction - upgrade either succeeds, or the user can stay at the old version // otherwise if half of the migrations succeed, user can't use any version - DB is too "new" for the old app, // and too old for the new app version. + + cls.setMigrationRunning(true); + sql.transactional(() => { for (const mig of migrations) { try { diff --git a/src/services/notes.js b/src/services/notes.js index 04f457f81..93b8313be 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -895,6 +895,11 @@ function scanForLinks(note, content) { * Things which have to be executed after updating content, but asynchronously (separate transaction) */ async function asyncPostProcessContent(note, content) { + if (cls.isMigrationRunning()) { + // this is rarely needed for migrations, but can cause trouble by e.g. triggering downloads + return; + } + if (note.hasStringContent() && !utils.isString(content)) { content = content.toString(); }