From 316996273843c3ee6ea9c27d2606abbd7266a51c Mon Sep 17 00:00:00 2001 From: Vishnu Mohandas Date: Mon, 8 Feb 2021 20:17:19 +0530 Subject: [PATCH] Persist the maxUpdationTime for all collections (factoring in the deleted ones) --- lib/services/collections_service.dart | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/services/collections_service.dart b/lib/services/collections_service.dart index 4a6719f53..e8f425d59 100644 --- a/lib/services/collections_service.dart +++ b/lib/services/collections_service.dart @@ -23,6 +23,7 @@ import 'package:shared_preferences/shared_preferences.dart'; class CollectionsService { static final _collectionSyncTimeKeyPrefix = "collection_sync_time_"; + static final _collectionsSyncTimeKey = "collections_sync_time"; final _logger = Logger("CollectionsService"); @@ -55,11 +56,13 @@ class CollectionsService { Future> sync() async { _logger.info("Syncing"); final lastCollectionUpdationTime = - await _db.getLastCollectionUpdationTime(); + _prefs.getInt(_collectionsSyncTimeKey) ?? 0; + // Might not have synced the collection fully final fetchedCollections = await _fetchCollections(lastCollectionUpdationTime ?? 0); final updatedCollections = List(); + int maxUpdationTime = lastCollectionUpdationTime; for (final collection in fetchedCollections) { if (collection.isDeleted) { await _filesDB.deleteCollection(collection.id); @@ -69,8 +72,12 @@ class CollectionsService { } else { updatedCollections.add(collection); } + maxUpdationTime = collection.updationTime > maxUpdationTime + ? collection.updationTime + : maxUpdationTime; } await _db.insert(updatedCollections); + _prefs.setInt(_collectionsSyncTimeKey, maxUpdationTime); final collections = await _db.getAllCollections(); for (final collection in collections) { _cacheCollectionAttributes(collection);