Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix sync double initialization issue
azivner9b425025c983
diff --git a/src/routes/api/setup.js b/src/routes/api/setup.jsindex 472b4dc829..c33cfaca1f 100644--- a/src/routes/api/setup.js+++ b/src/routes/api/setup.js@@ -6,7 +6,8 @@ const log = require('../../services/log');async function getStatus() {return {- isInitialized: await sqlInit.isDbInitialized()+ isInitialized: await sqlInit.isDbInitialized(),+ schemaExists: await sqlInit.schemaExists()};}diff --git a/src/services/setup.js b/src/services/setup.jsindex 6a558db4bb..10adaac4a1 100644--- a/src/services/setup.js+++ b/src/services/setup.js@@ -6,10 +6,10 @@ const repository = require('./repository');const optionService = require('./options');const syncOptions = require('./sync_options');-async function isSyncServerInitialized() {+async function hasSyncServerSchemaAndSeed() {const response = await requestToSyncServer('GET', '/api/setup/status');- return response.isInitialized;+ return response.schemaExists;}function triggerSync() {@@ -23,7 +23,7 @@ function triggerSync() {});}-async function setupSyncToSyncServer() {+async function sendSeedToSyncServer() {log.info("Initiating sync to server");await requestToSyncServer('POST', '/api/setup/sync-seed', {@@ -105,9 +105,9 @@ async function getSyncSeedOptions() {}module.exports = {- isSyncServerInitialized,+ hasSyncServerSchemaAndSeed,triggerSync,- setupSyncToSyncServer,+ sendSeedToSyncServer,setupSyncFromSyncServer,getSyncSeedOptions};\ No newline at end of filediff --git a/src/services/sync.js b/src/services/sync.jsindex 5cf8055d1a..201972758b 100644--- a/src/services/sync.js+++ b/src/services/sync.js@@ -71,8 +71,8 @@ async function sync() {async function login() {const setupService = require('./setup'); // circular dependency issue- if (!await setupService.isSyncServerInitialized()) {- await setupService.setupSyncToSyncServer();+ if (!await setupService.hasSyncServerSchemaAndSeed()) {+ await setupService.sendSeedToSyncServer();}return await doLogin();