From c6eba7bc569214c1ad0287c7e43018f882feadcd Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Tue, 30 Aug 2022 11:52:19 -0700 Subject: [PATCH 1/2] Add a check for new entries in the changes table to ensure swift syncing of non-Dexie observable changes. --- .../frontend/shared/data/serverSync.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/contentcuration/contentcuration/frontend/shared/data/serverSync.js b/contentcuration/contentcuration/frontend/shared/data/serverSync.js index 87a1dd22f8..f17b717b7e 100644 --- a/contentcuration/contentcuration/frontend/shared/data/serverSync.js +++ b/contentcuration/contentcuration/frontend/shared/data/serverSync.js @@ -306,6 +306,16 @@ if (process.env.NODE_ENV !== 'production' && typeof window !== 'undefined') { async function handleChanges(changes) { changes.map(applyResourceListener); const syncableChanges = changes.filter(isSyncableChange); + // Here we are handling changes triggered by Dexie Observable + // this is listening to all of our IndexedDB tables, both for resources + // and for our special Changes table. + // Here we look for any newly created changes in the changes table, which may require + // a sync to send them to the backend - this is particularly important for + // MOVE, COPY, PUBLISH, and SYNC changes where we may be executing them inside an IGNORED_SOURCE + // because they also make UPDATE and CREATE changes that we wish to make in the client only. + const newChangeTableEntries = changes.some( + c => c.table === CHANGES_TABLE && c.type === CHANGE_TYPES.CREATED + ); if (syncableChanges.length) { // Flatten any changes before we store them in the changes table @@ -323,7 +333,7 @@ async function handleChanges(changes) { // If we detect changes were written to the changes table // then we'll trigger sync - if (syncableChanges.length) { + if (syncableChanges.length || newChangeTableEntries) { debouncedSyncChanges(); } } From 56d87844319261a52d1e40535a3c5ca1e62c569e Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Wed, 31 Aug 2022 10:29:59 -0700 Subject: [PATCH 2/2] Add additional check to only try to sync unsynced changes. --- .../contentcuration/frontend/shared/data/serverSync.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contentcuration/contentcuration/frontend/shared/data/serverSync.js b/contentcuration/contentcuration/frontend/shared/data/serverSync.js index f17b717b7e..b022d6154f 100644 --- a/contentcuration/contentcuration/frontend/shared/data/serverSync.js +++ b/contentcuration/contentcuration/frontend/shared/data/serverSync.js @@ -313,8 +313,9 @@ async function handleChanges(changes) { // a sync to send them to the backend - this is particularly important for // MOVE, COPY, PUBLISH, and SYNC changes where we may be executing them inside an IGNORED_SOURCE // because they also make UPDATE and CREATE changes that we wish to make in the client only. + // Only do this for changes that are not marked as synced. const newChangeTableEntries = changes.some( - c => c.table === CHANGES_TABLE && c.type === CHANGE_TYPES.CREATED + c => c.table === CHANGES_TABLE && c.type === CHANGE_TYPES.CREATED && !c.obj.synced ); if (syncableChanges.length) {