Perf: Only refresh cache for fetched collections

This commit is contained in:
Neeraj Gupta 2023-05-24 08:09:18 +05:30
parent bfb4a52b9a
commit 1551c0c5ee

View file

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