Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob][photos] Refresh bg-updated caches on resume

Prateek Sunald30143af49a4
diff --git a/mobile/apps/photos/lib/app.dart b/mobile/apps/photos/lib/app.dart
index aba650356b..18381b9c3a 100644
--- a/mobile/apps/photos/lib/app.dart
+++ b/mobile/apps/photos/lib/app.dart
@@ -212,11 +212,11 @@ class _EnteAppState extends State<EnteApp> with WidgetsBindingObserver {
final futures = <Future<void>>[];
if (magicCacheService.lastMagicCacheUpdateTimeInMicroseconds >
lastAppOpenTimeInMicroseconds) {
- futures.add(magicCacheService.updateCache(forced: true));
+ futures.add(magicCacheService.refreshCache());
}
if (memoriesCacheService.lastMemoriesCacheUpdateTime >
lastAppOpenTimeInMicroseconds) {
- futures.add(memoriesCacheService.updateCache(forced: true));
+ futures.add(memoriesCacheService.refreshCache());
}
if (futures.isEmpty) {
return;
diff --git a/mobile/apps/photos/lib/services/magic_cache_service.dart b/mobile/apps/photos/lib/services/magic_cache_service.dart
index 64d9e2704c..a6202591ac 100644
--- a/mobile/apps/photos/lib/services/magic_cache_service.dart
+++ b/mobile/apps/photos/lib/services/magic_cache_service.dart
@@ -304,6 +304,21 @@ class MagicCacheService {
}
}
+ Future<void> refreshCache() async {
+ if (!enableDiscover) {
+ return;
+ }
+ try {
+ final prompts = await _readPromptFromDiskOrNetwork();
+ final magicCaches = await _readResultFromDisk();
+ _promptFuture = Future.value(prompts);
+ _magicCacheFuture = Future.value(magicCaches);
+ Bus.instance.fire(MagicCacheUpdatedEvent());
+ } catch (e, s) {
+ _logger.info("Error refreshing magic cache", e, s);
+ }
+ }
+
Future<List<Prompt>> getPrompts() async {
if (_promptFuture != null) {
return _promptFuture!;
diff --git a/mobile/apps/photos/lib/services/memories_cache_service.dart b/mobile/apps/photos/lib/services/memories_cache_service.dart
index bacdd9eada..aafc2e96e1 100644
--- a/mobile/apps/photos/lib/services/memories_cache_service.dart
+++ b/mobile/apps/photos/lib/services/memories_cache_service.dart
@@ -597,6 +597,24 @@ class MemoriesCacheService {
});
}
+ Future<void> refreshCache() async {
+ if (!showAnyMemories) {
+ return;
+ }
+ if (!enableSmartMemories) {
+ return;
+ }
+
+ return _memoriesUpdateLock.synchronized(() async {
+ try {
+ _cachedMemories = await _getMemoriesFromCache();
+ Bus.instance.fire(MemoriesChangedEvent());
+ } catch (e, s) {
+ _logger.info("Error refreshing memories cache", e, s);
+ }
+ });
+ }
+
static Map<int, String> _localIntIdToLocalId = {};
static final Map<String, int> _localIdToIntIdCache = {};