From b13e92400105881705ed66147166721f8731fd5c Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Fri, 20 Sep 2024 10:24:41 -0300 Subject: [PATCH] fix: build search and also return it in countAuthorStats() function --- src/utils/stats.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/utils/stats.ts b/src/utils/stats.ts index a44f8882..4573bb60 100644 --- a/src/utils/stats.ts +++ b/src/utils/stats.ts @@ -269,19 +269,27 @@ export async function updateEventStats( /** Calculate author stats from the database. */ export async function countAuthorStats( - { pubkey, kysely, store }: RefreshAuthorStatsOpts, -): Promise> { - const [{ count: followers_count }, { count: notes_count }, [followList]] = await Promise.all([ + { pubkey, store }: RefreshAuthorStatsOpts, +): Promise { + const [{ count: followers_count }, { count: notes_count }, [followList], [kind0]] = await Promise.all([ store.count([{ kinds: [3], '#p': [pubkey] }]), store.count([{ kinds: [1], authors: [pubkey] }]), store.query([{ kinds: [3], authors: [pubkey], limit: 1 }]), + store.query([{ kinds: [0], authors: [pubkey], limit: 1 }]), ]); + let search: string = ''; + const metadata = n.json().pipe(n.metadata()).catch({}).safeParse(kind0?.content); + if (metadata.success) { + const { name, nip05 } = metadata.data; + search = [name, nip05].filter(Boolean).join(' ').trim(); + } return { pubkey, followers_count, following_count: getTagSet(followList?.tags ?? [], 'p').size, notes_count, + search, }; }