Переглянути джерело

Perf: Only refresh cache for fetched collections (#1136)

Neeraj Gupta 2 роки тому
батько
коміт
d41e974657
1 змінених файлів з 5 додано та 6 видалено
  1. 5 6
      lib/services/collections_service.dart

+ 5 - 6
lib/services/collections_service.dart

@@ -108,13 +108,13 @@ class CollectionsService {
     final updatedCollections = <Collection>[];
     final updatedCollections = <Collection>[];
     int maxUpdationTime = lastCollectionUpdationTime;
     int maxUpdationTime = lastCollectionUpdationTime;
     final ownerID = _config.getUserID();
     final ownerID = _config.getUserID();
-    bool fireEventForCollectionDeleted = false;
+    bool shouldFireDeleteEvent = false;
     for (final collection in fetchedCollections) {
     for (final collection in fetchedCollections) {
       if (collection.isDeleted) {
       if (collection.isDeleted) {
         await _filesDB.deleteCollection(collection.id);
         await _filesDB.deleteCollection(collection.id);
         await setCollectionSyncTime(collection.id, null);
         await setCollectionSyncTime(collection.id, null);
         if (_collectionIDToCollections.containsKey(collection.id)) {
         if (_collectionIDToCollections.containsKey(collection.id)) {
-          fireEventForCollectionDeleted = true;
+          shouldFireDeleteEvent = true;
         }
         }
       }
       }
       // remove reference for incoming collections when unshared/deleted
       // remove reference for incoming collections when unshared/deleted
@@ -129,7 +129,7 @@ class CollectionsService {
           ? collection.updationTime
           ? collection.updationTime
           : maxUpdationTime;
           : maxUpdationTime;
     }
     }
-    if (fireEventForCollectionDeleted) {
+    if (shouldFireDeleteEvent) {
       Bus.instance.fire(
       Bus.instance.fire(
         LocalPhotosUpdatedEvent(
         LocalPhotosUpdatedEvent(
           List<File>.empty(),
           List<File>.empty(),
@@ -140,12 +140,11 @@ class CollectionsService {
     await _updateDB(updatedCollections);
     await _updateDB(updatedCollections);
     _prefs.setInt(_collectionsSyncTimeKey, maxUpdationTime);
     _prefs.setInt(_collectionsSyncTimeKey, maxUpdationTime);
     watch.logAndReset("till DB insertion ${updatedCollections.length}");
     watch.logAndReset("till DB insertion ${updatedCollections.length}");
-    final collections = await _db.getAllCollections();
-    for (final collection in collections) {
+    for (final collection in fetchedCollections) {
       _cacheCollectionAttributes(collection);
       _cacheCollectionAttributes(collection);
     }
     }
     _logger.info("Collections synced");
     _logger.info("Collections synced");
-    watch.log("collection cache refresh");
+    watch.log("${fetchedCollections.length} collection cached refreshed ");
     if (fetchedCollections.isNotEmpty) {
     if (fetchedCollections.isNotEmpty) {
       Bus.instance.fire(
       Bus.instance.fire(
         CollectionUpdatedEvent(
         CollectionUpdatedEvent(