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
chore(sync): drop the client-side re-stamp of future changes
Elian Doran49ddc9971a91
diff --git a/packages/trilium-core/src/services/entity_changes.ts b/packages/trilium-core/src/services/entity_changes.tsindex 5435cb3997..5f4807ace7 100644--- a/packages/trilium-core/src/services/entity_changes.ts+++ b/packages/trilium-core/src/services/entity_changes.ts@@ -97,24 +97,6 @@ function putBlobEntityChange(blobId: string) {} as EntityChange);}-/**- * Moves every entity change dated later than now back to now. Such a change was written while the- * clock ran ahead, and sync resolves conflicts by `utcDateChanged`, so it would otherwise win- * against every real edit made before the clock catches up with it.- */-function restampFutureEntityChanges() {- const now = dateUtils.utcNowDateTime();- const sql = getSql();- const count = sql.getValue<number>("SELECT COUNT(*) FROM entity_changes WHERE utcDateChanged > ?", [now]) ?? 0;-- if (count === 0) {- return;- }-- sql.execute("UPDATE entity_changes SET utcDateChanged = ? WHERE utcDateChanged > ?", [now, now]);- getLog().info(`Moved ${count} entity changes dated in the future back to ${now}`);-}-function putNoteReorderingEntityChange(parentNoteId: string, componentId?: string) {putEntityChange({entityName: "note_reordering",@@ -277,6 +259,5 @@ export default {fillAllEntityChanges,addEntityChangesForSector,getMaxEntityChangeId: () => maxEntityChangeId,- recalculateMaxEntityChangeId,- restampFutureEntityChanges+ recalculateMaxEntityChangeId};diff --git a/packages/trilium-core/src/services/sync.spec.ts b/packages/trilium-core/src/services/sync.spec.tsindex 3aa5c6d5d8..bace7747ea 100644--- a/packages/trilium-core/src/services/sync.spec.ts+++ b/packages/trilium-core/src/services/sync.spec.ts@@ -45,14 +45,12 @@ let changedIdx = 0;let checkIdx = 0;const requestLog: Array<{ method: string; url: string; body?: ExecOpts["body"] }> = [];-/** The records actually sent to the sync server, across every push of the run. */-const pushedRecords = () => requestLog+/** The entity IDs actually sent to the sync server, across every push of the run. */+const pushedEntityIds = () => requestLog.filter((r) => r.url.includes("/api/sync/update"))// syncRequest always serializes the body itself, so a push body is a JSON string.- .flatMap((r) => (typeof r.body === "string" ? JSON.parse(r.body || "{}").entities ?? [] : []) as EntityChangeRecord[]);--/** The entity IDs actually sent to the sync server, across every push of the run. */-const pushedEntityIds = () => pushedRecords().map((record) => record.entityChange.entityId);+ .flatMap((r) => (typeof r.body === "string" ? JSON.parse(r.body || "{}").entities ?? [] : []) as EntityChangeRecord[])+ .map((record) => record.entityChange.entityId);const fakeRequest: RequestProvider = fakeRequestProvider({exec: (<T,>(opts: ExecOpts): Promise<T> => {@@ -394,9 +392,7 @@ describe("sync service", () => {});await expect(runSync()).resolves.toEqual({ success: true });- const pushedNote = pushedRecords().find((record) => record.entityChange.entityId === noteId);- expect(pushedNote).toBeDefined();- expect.soft((pushedNote?.entityChange.utcDateChanged ?? clockAhead) < clockAhead).toBe(true);+ expect(pushedEntityIds()).toContain(noteId);const serverBlobId = "suClockAheadServerEdit";const later = dateUtils.utcNowDateTime();diff --git a/packages/trilium-core/src/services/sync.ts b/packages/trilium-core/src/services/sync.tsindex e049845855..e50bc7a018 100644--- a/packages/trilium-core/src/services/sync.ts+++ b/packages/trilium-core/src/services/sync.ts@@ -111,9 +111,6 @@ async function sync() {const syncContext = await login();- // The login succeeded, so the clock agrees with the sync server's.- entityChangesService.restampFutureEntityChanges();-await pushChanges(syncContext);await pullChanges(syncContext);