Skip to content

Build your personal knowledge base with Trilium Notes

created sync table

azivnerd88d562d63c9
diff --git a/migrations/0020__sync.sql b/migrations/0020__sync.sql
new file mode 100644
index 0000000000..e5d76f0cce
--- /dev/null
+++ b/migrations/0020__sync.sql
@@ -0,0 +1,15 @@
+CREATE TABLE `sync` (
+ `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
+ `entity_name` TEXT NOT NULL,
+ `entity_id` TEXT NOT NULL,
+ `sync_date` INTEGER NOT NULL
+);
+
+CREATE UNIQUE INDEX `IDX_sync_entity_name_id` ON `sync` (
+ `entity_name`,
+ `entity_id`
+);
+
+CREATE INDEX `IDX_sync_sync_date` ON `sync` (
+ `sync_date`
+);
\ No newline at end of file
diff --git a/services/migration.js b/services/migration.js
index b3a48211d5..22682dccd5 100644
--- a/services/migration.js
+++ b/services/migration.js
@@ -3,7 +3,7 @@ const sql = require('./sql');
const fs = require('fs-extra');
const log = require('./log');
-const APP_DB_VERSION = 19;
+const APP_DB_VERSION = 20;
const MIGRATIONS_DIR = "./migrations";
async function migrate() {
diff --git a/services/sync.js b/services/sync.js
index d09ef543df..b3b7b3ee17 100644
--- a/services/sync.js
+++ b/services/sync.js
@@ -129,6 +129,13 @@ async function pushSync(cookieJar, syncLog) {
lastSyncedPush = oldestUnsyncedDateModified;
+ // if the sync started in the same second as the last changes then it's possible we synced only parts
+ // of this second's changes. In that case we'll leave the last_synced_push as it is and stop the sync
+ // so next time we'll re-do this second again, this guaranteeing all changes have been pushed
+ if (lastSyncedPush === syncStarted) {
+ return;
+ }
+
await sql.setOption('last_synced_push', lastSyncedPush);
});
}
@@ -185,7 +192,7 @@ async function sync() {
await pushSync(cookieJar, syncLog);
- //await pullSync(cookieJar, syncLog);
+ await pullSync(cookieJar, syncLog);
}
catch (e) {
logSync("sync failed: " + e.stack, syncLog);