Skip to content

Commit

Permalink
Bugfix dexie-cloud "shopping card" use case:...
Browse files Browse the repository at this point in the history
Failed to sync local data after logging in user
  • Loading branch information
dfahlander committed Oct 17, 2022
1 parent 88f0c6b commit e8eeb19
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions addons/dexie-cloud/src/sync/listSyncifiedChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function listSyncifiedChanges(
return (
!ignoredRealms.has(item.realmId || '') &&
//(id[0] !== '#' || !!item.$ts) && // Private obj need no sync if not changed
isValidSyncableID(id)
isValidAtID(extractKey(item), dexieCloudTableSchema?.idPrefix)
);
})
: table.filter((item) => {
Expand All @@ -41,7 +41,7 @@ export async function listSyncifiedChanges(
return (
!ignoredRealms.has(item.realmId || '') &&
//(id[0] !== '#' || !!item.$ts) && // Private obj need no sync if not changed
isValidAtID(extractKey(item), dexieCloudTableSchema?.idPrefix)
isValidSyncableID(id)
);
});
const unsyncedObjects = await query.toArray();
Expand Down
16 changes: 9 additions & 7 deletions addons/dexie-cloud/src/sync/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ async function _sync(
// Prepare for syncification by modifying locally unauthorized objects:
//
const persistedSyncState = await db.getPersistedSyncState();
const tablesToSyncify =
!isInitialSync && currentUser.isLoggedIn
? getTablesToSyncify(db, persistedSyncState)
: [];
const readyForSyncification = !isInitialSync && currentUser.isLoggedIn;
const tablesToSyncify = readyForSyncification
? getTablesToSyncify(db, persistedSyncState)
: [];
throwIfCancelled(cancelToken);
const doSyncify = tablesToSyncify.length > 0;

Expand Down Expand Up @@ -327,9 +327,11 @@ async function _sync(
inviteRealms: [],
clientIdentity,
};
newSyncState.syncedTables = tablesToSync
.map((tbl) => tbl.name)
.concat(tablesToSyncify.map((tbl) => tbl.name));
if (readyForSyncification) {
newSyncState.syncedTables = tablesToSync
.map((tbl) => tbl.name)
.concat(tablesToSyncify.map((tbl) => tbl.name));
}
newSyncState.latestRevisions = latestRevisions;
newSyncState.remoteDbId = res.dbId;
newSyncState.initiallySynced = true;
Expand Down

0 comments on commit e8eeb19

Please sign in to comment.