Sync progress once per minute

This commit is contained in:
chrox
2024-12-24 19:38:16 +01:00
parent 116b831102
commit b40654a671
3 changed files with 8 additions and 6 deletions
@@ -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);
+6 -4
View File
@@ -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;
}
+1 -1
View File
@@ -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;