Browse Source

clear publication cache when search data updated

master^2
Silberengel 2 months ago
parent
commit
9fb78961fc
  1. 5
      src/lib/components/publications/PublicationFeed.svelte
  2. 13
      src/lib/utils/searchCache.ts

5
src/lib/components/publications/PublicationFeed.svelte

@ -278,6 +278,11 @@
// Sort by created_at descending // Sort by created_at descending
allIndexEvents.sort((a, b) => b.created_at! - a.created_at!); 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 // Update the view immediately with new events
eventsInView = allIndexEvents.slice(0, publicationsToDisplay); eventsInView = allIndexEvents.slice(0, publicationsToDisplay);
endOfFeed = allIndexEvents.length <= publicationsToDisplay; endOfFeed = allIndexEvents.length <= publicationsToDisplay;

13
src/lib/utils/searchCache.ts

@ -98,6 +98,19 @@ class SearchCache {
size(): number { size(): number {
return this.cache.size; 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(); export const searchCache = new SearchCache();

Loading…
Cancel
Save