Skip to content

Commit afaf160

Browse files
laurenspriemua741
authored andcommitted
[mob][photos] Hide from memories fix (#8281)
## Description Purge hidden person from memories immediately
1 parent 260157d commit afaf160

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

mobile/apps/photos/lib/services/machine_learning/face_ml/person/person_service.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import "dart:async";
12
import "dart:convert";
23
import "dart:developer";
34

@@ -558,6 +559,11 @@ class PersonService {
558559
if (hideFromMemories != null &&
559560
hideFromMemories != person.data.hideFromMemories) {
560561
memoriesCacheService.queueUpdateCache();
562+
if (hideFromMemories) {
563+
unawaited(
564+
memoriesCacheService.purgePersonFromMemoriesCache(id),
565+
);
566+
}
561567
}
562568
return updatedPerson;
563569
}

mobile/apps/photos/lib/services/memories_cache_service.dart

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,68 @@ class MemoriesCacheService {
154154
unawaited(_prefs.setBool(_shouldUpdateCacheKey, true));
155155
}
156156

157+
Future<void> purgePersonFromMemoriesCache(String personID) async {
158+
await _memoriesUpdateLock.synchronized(() async {
159+
final removedMemoryIDs = <String>{};
160+
bool cacheChanged = false;
161+
162+
if (_cachedMemories != null && _cachedMemories!.isNotEmpty) {
163+
final filtered = <SmartMemory>[];
164+
for (final memory in _cachedMemories!) {
165+
if (memory is PeopleMemory && memory.personID == personID) {
166+
removedMemoryIDs.add(memory.id);
167+
continue;
168+
}
169+
filtered.add(memory);
170+
}
171+
if (filtered.length != _cachedMemories!.length) {
172+
_cachedMemories = filtered;
173+
cacheChanged = true;
174+
}
175+
}
176+
177+
final cache = await _readCacheFromDisk();
178+
if (cache != null) {
179+
final originalToShowLength = cache.toShowMemories.length;
180+
final originalLogLength = cache.peopleShownLogs.length;
181+
for (final memory in cache.toShowMemories) {
182+
if (memory.type == MemoryType.people && memory.personID == personID) {
183+
removedMemoryIDs.add(memory.id);
184+
}
185+
}
186+
cache.toShowMemories.removeWhere(
187+
(memory) =>
188+
memory.type == MemoryType.people && memory.personID == personID,
189+
);
190+
cache.peopleShownLogs.removeWhere(
191+
(log) => log.personID == personID,
192+
);
193+
final shouldWriteCache =
194+
cache.toShowMemories.length != originalToShowLength ||
195+
cache.peopleShownLogs.length != originalLogLength;
196+
if (shouldWriteCache) {
197+
await writeToJsonFile<MemoriesCache>(
198+
await _getCachePath(),
199+
cache,
200+
MemoriesCache.encodeToJsonString,
201+
);
202+
cacheChanged = true;
203+
}
204+
}
205+
206+
if (removedMemoryIDs.isNotEmpty) {
207+
await NotificationService.instance.clearAllScheduledNotifications(
208+
containingPayload: personID,
209+
logLines: false,
210+
);
211+
}
212+
213+
if (cacheChanged) {
214+
Bus.instance.fire(MemoriesChangedEvent());
215+
}
216+
});
217+
}
218+
157219
Future<List<SmartMemory>> getMemories({bool onlyUseCache = false}) async {
158220
_logger.info("getMemories called");
159221
if (!showAnyMemories) {

0 commit comments

Comments
 (0)