diff --git a/src/client.ts b/src/client.ts index 9a624249..e014d163 100644 --- a/src/client.ts +++ b/src/client.ts @@ -5,6 +5,7 @@ import { poolRelays } from './config.ts'; import { eventDateComparator, nostrNow } from './utils.ts'; +const db = await Deno.openKv(); const pool = new RelayPool(poolRelays); type Filter = { @@ -86,7 +87,15 @@ const getAuthor = async (pubkey: string): Promise | undefined> => /** Get users the given pubkey follows. */ const getFollows = async (pubkey: string): Promise | undefined> => { const [event] = await getFilter({ authors: [pubkey], kinds: [3] }, { timeout: 5000 }); - return event; + + // TODO: figure out a better, more generic & flexible way to handle event (and timeouts?) + // Prewarm cache in GET `/api/v1/accounts/verify_credentials` + if (event) { + await db.set(['event3', pubkey], event); + return event; + } else { + return (await db.get>(['event3', pubkey])).value || undefined; + } }; interface PaginationParams {