From 302ca4a0823e231cdd7ef8a6dbbe03b88b25dbcf Mon Sep 17 00:00:00 2001 From: Abhinav Date: Mon, 30 Jan 2023 15:12:17 +0530 Subject: [PATCH] clear last sync time of a collection after it has been deleted --- src/services/collectionService.ts | 10 ++++++++++ src/services/fileService.ts | 12 +++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/services/collectionService.ts b/src/services/collectionService.ts index 89d3fc035..375f3bb58 100644 --- a/src/services/collectionService.ts +++ b/src/services/collectionService.ts @@ -60,6 +60,14 @@ const ENDPOINT = getEndpoint(); const COLLECTION_TABLE = 'collections'; const COLLECTION_UPDATION_TIME = 'collection-updation-time'; +export const getCollectionLastSyncTime = async (collection: Collection) => + (await localForage.getItem(`${collection.id}-time`)) ?? 0; + +export const setCollectionLastSyncTime = async ( + collection: Collection, + time: number +) => await localForage.setItem(`${collection.id}-time`, time); + const getCollectionWithSecrets = async ( collection: EncryptedCollection, masterKey: string @@ -197,6 +205,8 @@ export const syncCollections = async () => { if (!collection.isDeleted) { collections.push(collection); updationTime = Math.max(updationTime, collection.updationTime); + } else { + setCollectionLastSyncTime(collection, 0); } } diff --git a/src/services/fileService.ts b/src/services/fileService.ts index 68453895e..724de75d0 100644 --- a/src/services/fileService.ts +++ b/src/services/fileService.ts @@ -19,6 +19,10 @@ import { addLogLine } from 'utils/logging'; import { isCollectionHidden } from 'utils/collection'; import { CustomError } from 'utils/error'; import ComlinkCryptoWorker from 'utils/comlink/ComlinkCryptoWorker'; +import { + getCollectionLastSyncTime, + setCollectionLastSyncTime, +} from './collectionService'; const ENDPOINT = getEndpoint(); const FILES_TABLE = 'files'; @@ -47,9 +51,6 @@ const setLocalFiles = async (files: EnteFile[]) => { } }; -const getCollectionLastSyncTime = async (collection: Collection) => - (await localForage.getItem(`${collection.id}-time`)) ?? 0; - export const syncFiles = async ( collections: Collection[], setFiles: SetFiles @@ -93,10 +94,7 @@ export const syncFiles = async ( files.push(file); } await setLocalFiles(files); - await localForage.setItem( - `${collection.id}-time`, - collection.updationTime - ); + setCollectionLastSyncTime(collection, collection.updationTime); setFiles(preservePhotoswipeProps([...sortFiles(mergeMetadata(files))])); } return sortFiles(mergeMetadata(files));