瀏覽代碼

Persist the maxUpdationTime for all collections (factoring in the deleted ones)

Vishnu Mohandas 4 年之前
父節點
當前提交
3169962738
共有 1 個文件被更改,包括 8 次插入1 次删除
  1. 8 1
      lib/services/collections_service.dart

+ 8 - 1
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<List<Collection>> 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<Collection>();
+    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);