mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
fix: build search and also return it in countAuthorStats() function
This commit is contained in:
parent
578f269a65
commit
b13e924001
1 changed files with 11 additions and 3 deletions
|
|
@ -269,19 +269,27 @@ export async function updateEventStats(
|
|||
|
||||
/** Calculate author stats from the database. */
|
||||
export async function countAuthorStats(
|
||||
{ pubkey, kysely, store }: RefreshAuthorStatsOpts,
|
||||
): Promise<Omit<DittoTables['author_stats'], 'search'>> {
|
||||
const [{ count: followers_count }, { count: notes_count }, [followList]] = await Promise.all([
|
||||
{ pubkey, store }: RefreshAuthorStatsOpts,
|
||||
): Promise<DittoTables['author_stats']> {
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue