From 9fb78961fcfdfd6f65e7169c8f662638db555de7 Mon Sep 17 00:00:00 2001 From: Silberengel Date: Fri, 16 Jan 2026 19:17:00 +0100 Subject: [PATCH] clear publication cache when search data updated --- .../components/publications/PublicationFeed.svelte | 5 +++++ src/lib/utils/searchCache.ts | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/lib/components/publications/PublicationFeed.svelte b/src/lib/components/publications/PublicationFeed.svelte index 0d0873b..92721dd 100644 --- a/src/lib/components/publications/PublicationFeed.svelte +++ b/src/lib/components/publications/PublicationFeed.svelte @@ -278,6 +278,11 @@ // Sort by created_at descending allIndexEvents.sort((a, b) => b.created_at! - a.created_at!); + // AI-NOTE: Clear publication search cache when new events are loaded to prevent stale results + // This ensures searches will re-run with the updated event set + searchCache.clearType("publication"); + console.debug(`[PublicationFeed] Cleared publication search cache after loading ${newEvents.length} new events`); + // Update the view immediately with new events eventsInView = allIndexEvents.slice(0, publicationsToDisplay); endOfFeed = allIndexEvents.length <= publicationsToDisplay; diff --git a/src/lib/utils/searchCache.ts b/src/lib/utils/searchCache.ts index 76eb3c0..03aea91 100644 --- a/src/lib/utils/searchCache.ts +++ b/src/lib/utils/searchCache.ts @@ -98,6 +98,19 @@ class SearchCache { size(): number { return this.cache.size; } + + /** + * Clear cache entries for a specific search type + */ + clearType(searchType: string): void { + const keysToDelete: string[] = []; + for (const [key] of this.cache.entries()) { + if (key.startsWith(`${searchType}:`)) { + keysToDelete.push(key); + } + } + keysToDelete.forEach((key) => this.cache.delete(key)); + } } export const searchCache = new SearchCache();