Skip to content

Commit

Permalink
fix keel realtime plugin needs to set the lastSync time after the fir…
Browse files Browse the repository at this point in the history
…st query to prevent refreshing right afterwards
  • Loading branch information
jmeistrich committed Jun 17, 2024
1 parent c0c3d8b commit 0fb37e1
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/sync-plugins/keel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,14 @@ export function syncedKeel<
const fieldCreatedAt: KeelKey = 'createdAt';
const fieldUpdatedAt: KeelKey = 'updatedAt';

const setupSubscribe = (doSubscribe: SubscribeFn, subscribeKey: string, lastSync?: number | undefined) => {
subscribeFn = doSubscribe;
subscribeFnKey$.set(subscribeKey);
if (realtimePlugin && lastSync) {
realtimePlugin.setLatestChange(subscribeKey, new Date(lastSync));
}
};

const list = listParam
? async (listParams: SyncedGetParams) => {
const { lastSync, refresh } = listParams;
Expand All @@ -356,8 +364,7 @@ export function syncedKeel<
// TODO: Error?
const { results, subscribe, subscribeKey } = await getAllPages(listParam, params);
if (subscribe) {
subscribeFn = () => subscribe({ refresh });
subscribeFnKey$.set(subscribeKey);
setupSubscribe(() => subscribe({ refresh }), subscribeKey, lastSync);
}

return results;
Expand All @@ -370,8 +377,7 @@ export function syncedKeel<
// @ts-expect-error TODOKEEL
const { data, error, subscribe, subscribeKey } = await getParam({ refresh });
if (subscribe) {
subscribeFn = () => subscribe({ refresh });
subscribeFnKey$.set(subscribeKey);
setupSubscribe(() => subscribe({ refresh }), subscribeKey);
}

if (error) {
Expand Down

0 comments on commit 0fb37e1

Please sign in to comment.