From 215d18480840d933651fd56c281b8f153fdc221f Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 6 Apr 2024 14:56:48 -0500 Subject: [PATCH] accountSearchController: utilize the searchStore --- src/controllers/api/accounts.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/controllers/api/accounts.ts b/src/controllers/api/accounts.ts index 92e2045..852c2b6 100644 --- a/src/controllers/api/accounts.ts +++ b/src/controllers/api/accounts.ts @@ -5,7 +5,7 @@ import { nip19, z } from '@/deps.ts'; import { getAuthor, getFollowedPubkeys } from '@/queries.ts'; import { booleanParamSchema, fileSchema } from '@/schema.ts'; import { jsonMetaContentSchema } from '@/schemas/nostr.ts'; -import { eventsDB } from '@/storages.ts'; +import { eventsDB, searchStore } from '@/storages.ts'; import { addTag, deleteTag, findReplyTag, getTagSet } from '@/tags.ts'; import { uploadFile } from '@/upload.ts'; import { nostrNow } from '@/utils.ts'; @@ -86,12 +86,22 @@ const accountSearchController: AppController = async (c) => { return c.json({ error: 'Missing `q` query parameter.' }, 422); } - const event = await lookupAccount(decodeURIComponent(q)); - if (event) { - return c.json([await renderAccount(event)]); - } + const query = decodeURIComponent(q); - return c.json([]); + const [event, events] = await Promise.all([ + lookupAccount(query), + searchStore.query([{ kinds: [0], search: query, limit: 20 }], { signal: c.req.raw.signal }), + ]); + + const results = await hydrateEvents({ + events: event ? [event, ...events] : events, + relations: ['author_stats'], + storage: eventsDB, + signal: c.req.raw.signal, + }); + + const accounts = await Promise.all(results.map((event) => renderAccount(event))); + return c.json(accounts); }; const relationshipsController: AppController = async (c) => {