fix: add missing methods to cache wrappers

Add back methods that are still being used in the codebase:
- RelayListCache.get() - used by ProfileViewer
- RelayListCache.clear() - used by relay-selection tests
- ReplaceableEventCache.clearKind() - new method for testing

Also remove redundant blossomServerCache.set() calls from ProfileViewer
since events are now auto-cached by ReplaceableEventCache subscription.
This commit is contained in:
Claude
2026-01-16 22:12:55 +00:00
parent 1283964d01
commit 5e193d64cd
3 changed files with 62 additions and 4 deletions

View File

@@ -150,8 +150,7 @@ export function ProfileViewer({ pubkey }: ProfileViewerProps) {
if (existingEvent) {
const servers = getServersFromEvent(existingEvent);
setBlossomServers(servers);
// Also update cache
blossomServerCache.set(existingEvent);
// Event is auto-cached by ReplaceableEventCache subscription
}
// Subscribe to EventStore for reactive updates
@@ -161,8 +160,7 @@ export function ProfileViewer({ pubkey }: ProfileViewerProps) {
if (event) {
const servers = getServersFromEvent(event);
setBlossomServers(servers);
// Also update cache
blossomServerCache.set(event);
// Event is auto-cached by ReplaceableEventCache subscription
} else {
setBlossomServers([]);
}

View File

@@ -104,6 +104,29 @@ class RelayListCache {
async invalidate(pubkey: string): Promise<void> {
return replaceableEventCache.invalidate(pubkey, RELAY_LIST_KIND);
}
/**
* Get cached relay list entry for a pubkey
* Returns the full cached entry with event and parsed data
*/
async get(
pubkey: string,
): Promise<{ event: any; read: string[]; write: string[] } | null> {
const event = await replaceableEventCache.getEvent(pubkey, RELAY_LIST_KIND);
if (!event) return null;
const read = this.normalizeRelays(getInboxes(event));
const write = this.normalizeRelays(getOutboxes(event));
return { event, read, write };
}
/**
* Clear all cached relay lists (for testing)
*/
async clear(): Promise<void> {
return replaceableEventCache.clearKind(RELAY_LIST_KIND);
}
}
// Singleton instance

View File

@@ -389,6 +389,43 @@ class ReplaceableEventCache {
}
}
/**
* Clear all cached events of a specific kind (for testing)
*/
async clearKind(kind: number): Promise<void> {
try {
const count = await db.replaceableEvents
.where("kind")
.equals(kind)
.delete();
// Also remove from memory cache
const keysToDelete: string[] = [];
for (const key of this.memoryCache.keys()) {
if (key.includes(`:${kind}:`)) {
keysToDelete.push(key);
}
}
for (const key of keysToDelete) {
this.memoryCache.delete(key);
const index = this.cacheOrder.indexOf(key);
if (index > -1) {
this.cacheOrder.splice(index, 1);
}
}
console.debug(
`[ReplaceableEventCache] Cleared ${count} kind:${kind} entries`,
);
} catch (error) {
console.error(
`[ReplaceableEventCache] Error clearing kind:${kind}:`,
error,
);
}
}
/**
* Clear all cached events
*/