From b40654a671a8cd015fa5f2a82afe475cd46d046c Mon Sep 17 00:00:00 2001 From: chrox Date: Tue, 24 Dec 2024 19:38:16 +0100 Subject: [PATCH] Sync progress once per minute --- .../src/app/reader/hooks/useProgressSync.ts | 2 +- apps/readest-app/src/hooks/useSync.ts | 10 ++++++---- apps/readest-app/src/services/constants.ts | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/readest-app/src/app/reader/hooks/useProgressSync.ts b/apps/readest-app/src/app/reader/hooks/useProgressSync.ts index 1d9f5ab0..6222ea18 100644 --- a/apps/readest-app/src/app/reader/hooks/useProgressSync.ts +++ b/apps/readest-app/src/app/reader/hooks/useProgressSync.ts @@ -15,7 +15,7 @@ export const useProgressSync = ( const { getConfig, setConfig } = useBookDataStore(); const { getView } = useReaderStore(); const { settings } = useSettingsStore(); - const { syncedConfigs, syncConfigs } = useSync(); + const { syncedConfigs, syncConfigs } = useSync(bookKey); const { user } = useAuth(); const view = getView(bookKey); const config = getConfig(bookKey); diff --git a/apps/readest-app/src/hooks/useSync.ts b/apps/readest-app/src/hooks/useSync.ts index e046d08d..0d720ffe 100644 --- a/apps/readest-app/src/hooks/useSync.ts +++ b/apps/readest-app/src/hooks/useSync.ts @@ -32,8 +32,7 @@ const computeMaxTimestamp = (records: BookDataRecord[]): number => { export function useSync(bookKey?: string) { const { settings } = useSettingsStore(); - const { getConfig } = useBookDataStore(); - + const { getConfig, setConfig } = useBookDataStore(); const config = bookKey ? getConfig(bookKey) : null; const [syncingBooks, setSyncingBooks] = useState(false); @@ -79,6 +78,7 @@ export function useSync(bookKey?: string) { const result = await syncClient.pullChanges(since, type, bookId); const maxTime = computeMaxTimestamp(result[type]); setLastSyncedAt(maxTime); + setSyncResult(result); switch (type) { case 'books': settings.lastSyncedAtBooks = maxTime; @@ -86,15 +86,17 @@ export function useSync(bookKey?: string) { case 'configs': if (!bookId) { settings.lastSyncedAtConfigs = maxTime; - } else if (config) { + } else if (bookKey && config) { config.lastSyncedAtConfig = maxTime; + setConfig(bookKey, config); } break; case 'notes': if (!bookId) { settings.lastSyncedAtNotes = maxTime; - } else if (config) { + } else if (bookKey && config) { config.lastSyncedAtNotes = maxTime; + setConfig(bookKey, config); } break; } diff --git a/apps/readest-app/src/services/constants.ts b/apps/readest-app/src/services/constants.ts index 155f506b..2d460ea3 100644 --- a/apps/readest-app/src/services/constants.ts +++ b/apps/readest-app/src/services/constants.ts @@ -87,4 +87,4 @@ export const DOWNLOAD_READEST_URL = 'https://readest.com?utm_source=readest_web' export const READEST_WEB_BASE_URL = 'https://web.readest.com'; -export const SYNC_PROGRESS_INTERVAL_SEC = 30; +export const SYNC_PROGRESS_INTERVAL_SEC = 60;