@@ -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