refactor: remove deprecated kind-specific cache tables and hooks

Clean up old caching infrastructure now that generic cache is in place:

Database changes:
- Mark relayLists and blossomServers tables as deprecated
- Remove tables from v16 schema (set to null for deletion)
- Keep table definitions for backward compatibility with old versions
- Mark CachedRelayList and CachedBlossomServerList interfaces as deprecated

Removed deprecated hooks:
- Delete useRelayListCacheSync.ts (no longer needed)
- Delete useBlossomServerCacheSync.ts (no longer needed)
- All caching now handled by useReplaceableEventCacheSync

Migration path:
- Old databases will automatically migrate to replaceableEvents table
- Wrapper classes (RelayListCache, BlossomServerCache) still work
- No breaking changes to consuming code
This commit is contained in:
Claude
2026-01-16 22:17:06 +00:00
parent 5e193d64cd
commit b813f7bd2b
3 changed files with 21 additions and 59 deletions

View File

@@ -1,24 +0,0 @@
/**
* Hook to keep blossom server cache in sync with EventStore
*
* Subscribes to kind:10063 events and automatically caches them in Dexie.
* Should be used once at app root level.
*/
import { useEffect } from "react";
import { useEventStore } from "applesauce-react/hooks";
import blossomServerCache from "@/services/blossom-server-cache";
export function useBlossomServerCacheSync() {
const eventStore = useEventStore();
useEffect(() => {
// Subscribe to EventStore for auto-caching
blossomServerCache.subscribeToEventStore(eventStore);
// Cleanup on unmount
return () => {
blossomServerCache.unsubscribe();
};
}, [eventStore]);
}

View File

@@ -1,24 +0,0 @@
/**
* Hook to keep relay list cache in sync with EventStore
*
* Subscribes to kind:10002 events and automatically caches them in Dexie.
* Should be used once at app root level.
*/
import { useEffect } from "react";
import { useEventStore } from "applesauce-react/hooks";
import relayListCache from "@/services/relay-list-cache";
export function useRelayListCacheSync() {
const eventStore = useEventStore();
useEffect(() => {
// Subscribe to EventStore for auto-caching
relayListCache.subscribeToEventStore(eventStore);
// Cleanup on unmount
return () => {
relayListCache.unsubscribe();
};
}, [eventStore]);
}

View File

@@ -37,14 +37,6 @@ export interface RelayAuthPreference {
updatedAt: number;
}
export interface CachedRelayList {
pubkey: string;
event: NostrEvent;
read: string[];
write: string[];
updatedAt: number;
}
export interface RelayLivenessEntry {
url: string;
state: "online" | "offline" | "dead";
@@ -54,6 +46,22 @@ export interface RelayLivenessEntry {
backoffUntil?: number;
}
/**
* @deprecated Use CachedReplaceableEvent instead
* Kept for backward compatibility with old database versions
*/
export interface CachedRelayList {
pubkey: string;
event: NostrEvent;
read: string[];
write: string[];
updatedAt: number;
}
/**
* @deprecated Use CachedReplaceableEvent instead
* Kept for backward compatibility with old database versions
*/
export interface CachedBlossomServerList {
pubkey: string;
event: NostrEvent;
@@ -105,8 +113,10 @@ class GrimoireDb extends Dexie {
nips!: Table<Nip>;
relayInfo!: Table<RelayInfo>;
relayAuthPreferences!: Table<RelayAuthPreference>;
/** @deprecated Use replaceableEvents table instead */
relayLists!: Table<CachedRelayList>;
relayLiveness!: Table<RelayLivenessEntry>;
/** @deprecated Use replaceableEvents table instead */
blossomServers!: Table<CachedBlossomServerList>;
replaceableEvents!: Table<CachedReplaceableEvent>;
spells!: Table<LocalSpell>;
@@ -347,16 +357,16 @@ class GrimoireDb extends Dexie {
spellbooks: "&id, slug, title, createdAt, isPublished, deletedAt",
});
// Version 16: Add generic replaceable event cache
// Version 16: Add generic replaceable event cache, deprecate old kind-specific tables
this.version(16).stores({
profiles: "&pubkey",
nip05: "&nip05",
nips: "&id",
relayInfo: "&url",
relayAuthPreferences: "&url",
relayLists: "&pubkey, updatedAt",
relayLists: null, // Deprecated - migrated to replaceableEvents
relayLiveness: "&url",
blossomServers: "&pubkey, updatedAt",
blossomServers: null, // Deprecated - migrated to replaceableEvents
replaceableEvents: "[pubkey+kind+d], [pubkey+kind], kind, updatedAt",
spells: "&id, alias, createdAt, isPublished, deletedAt",
spellbooks: "&id, slug, title, createdAt, isPublished, deletedAt",