perf: hydrate repost events in reblog endpoint & streaming

This commit is contained in:
P. Reis
2024-04-13 18:16:15 -03:00
parent 24efca5ea0
commit 37bee709cd
5 changed files with 38 additions and 18 deletions

View File

@@ -4,7 +4,7 @@ import { Conf } from '@/config.ts';
import { nip19 } from '@/deps.ts';
import { type DittoEvent } from '@/interfaces/DittoEvent.ts';
import { getMediaLinks, parseNoteContent } from '@/note.ts';
import { getAuthor, getEvent } from '@/queries.ts';
import { getAuthor } from '@/queries.ts';
import { jsonMediaDataSchema } from '@/schemas/nostr.ts';
import { eventsDB } from '@/storages.ts';
import { findReplyTag } from '@/tags.ts';
@@ -100,21 +100,12 @@ async function renderStatus(event: DittoEvent, viewerPubkey?: string) {
};
}
type reblogOpts = {
loadOriginalPostEvent?: boolean;
};
async function renderReblog(event: DittoEvent, opts: reblogOpts) {
const { loadOriginalPostEvent } = opts;
async function renderReblog(event: DittoEvent) {
if (!event.author) return;
const repostId = event.tags.find(([name]) => name === 'e')?.[1];
if (!repostId) return;
if (loadOriginalPostEvent) {
event.repost = await getEvent(repostId, { kind: 1 });
}
if (!event.repost) return;
const reblog = await renderStatus(event.repost);