2026-01-13 14:49:19 +01:00

36 lines
1.1 KiB
TypeScript

import type { Article } from '@/types/nostr'
import type { Event } from 'nostr-tools'
import { objectCache } from '../objectCache'
export async function getCachedArticleById(eventId: string): Promise<Article | null> {
const cachedById = await objectCache.getById('publication', eventId)
if (cachedById) {
return cachedById as Article
}
const cachedByHash = await objectCache.get('publication', eventId)
if (cachedByHash) {
return cachedByHash as Article
}
const cachedAuthor = await objectCache.getById('author', eventId)
if (cachedAuthor) {
return cachedAuthor as Article
}
const cachedAuthorByHash = await objectCache.get('author', eventId)
if (cachedAuthorByHash) {
return cachedAuthorByHash as Article
}
return null
}
export async function getCachedEventById(eventId: string): Promise<Event | null> {
const eventFromPublication = await objectCache.getEventById('publication', eventId)
if (eventFromPublication) {
return eventFromPublication
}
const eventFromAuthor = await objectCache.getEventById('author', eventId)
if (eventFromAuthor) {
return eventFromAuthor
}
return null
}