diff --git a/src/controllers/api/accounts.ts b/src/controllers/api/accounts.ts index 088d942b..0ca2f714 100644 --- a/src/controllers/api/accounts.ts +++ b/src/controllers/api/accounts.ts @@ -136,10 +136,7 @@ const accountSearchController: AppController = async (c) => { return c.json(pubkey ? [await accountFromPubkey(pubkey)] : []); } - const followList: string[] = []; - if (viewerPubkey) { - followList.push(...await getFollowedPubkeys(viewerPubkey)); - } + const followList: Set = viewerPubkey ? await getFollowedPubkeys(viewerPubkey) : new Set(); const pubkeys = (await getPubkeysBySearch(kysely, { q: query, limit, followList })).slice(0, limit); let events = event ? [event] : await store.query([{ kinds: [0], authors: pubkeys, limit }], { diff --git a/src/controllers/api/search.ts b/src/controllers/api/search.ts index ebcbc4ca..358a8882 100644 --- a/src/controllers/api/search.ts +++ b/src/controllers/api/search.ts @@ -96,10 +96,7 @@ async function searchEvents( if (type === 'accounts') { const kysely = await Storages.kysely(); - const followList: string[] = []; - if (viewerPubkey) { - followList.push(...await getFollowedPubkeys(viewerPubkey)); - } + const followList: Set = viewerPubkey ? await getFollowedPubkeys(viewerPubkey) : new Set(); pubkeys.push(...(await getPubkeysBySearch(kysely, { q, limit, followList }))); if (!filter?.authors) { diff --git a/src/utils/search.test.ts b/src/utils/search.test.ts index 4fdb9d80..4b9b1d30 100644 --- a/src/utils/search.test.ts +++ b/src/utils/search.test.ts @@ -11,11 +11,11 @@ Deno.test('fuzzy search works', async () => { search: 'patrickReiis patrickdosreis.com', }).execute(); - assertEquals(await getPubkeysBySearch(db.kysely, { q: 'pat rick', limit: 1, followList: [] }), []); - assertEquals(await getPubkeysBySearch(db.kysely, { q: 'patrick dos reis', limit: 1, followList: [] }), [ + assertEquals(await getPubkeysBySearch(db.kysely, { q: 'pat rick', limit: 1, followList: new Set() }), []); + assertEquals(await getPubkeysBySearch(db.kysely, { q: 'patrick dos reis', limit: 1, followList: new Set() }), [ '47259076c85f9240e852420d7213c95e95102f1de929fb60f33a2c32570c98c4', ]); - assertEquals(await getPubkeysBySearch(db.kysely, { q: 'dosreis.com', limit: 1, followList: [] }), [ + assertEquals(await getPubkeysBySearch(db.kysely, { q: 'dosreis.com', limit: 1, followList: new Set() }), [ '47259076c85f9240e852420d7213c95e95102f1de929fb60f33a2c32570c98c4', ]); }); diff --git a/src/utils/search.ts b/src/utils/search.ts index 81b9240a..a12e8c95 100644 --- a/src/utils/search.ts +++ b/src/utils/search.ts @@ -5,7 +5,7 @@ import { DittoTables } from '@/db/DittoTables.ts'; /** Get pubkeys whose name and NIP-05 is similar to 'q' */ export async function getPubkeysBySearch( kysely: Kysely, - opts: { q: string; limit: number; followList: string[] }, + opts: { q: string; limit: number; followList: Set }, ) { const { q, limit, followList } = opts; @@ -22,8 +22,8 @@ export async function getPubkeysBySearch( const pubkeys = new Set((await query.execute()).map(({ pubkey }) => pubkey)); - if (followList.length > 0) { - query = query.where('pubkey', 'in', followList); + if (followList.size > 0) { + query = query.where('pubkey', 'in', [...followList]); } const followingPubkeys = new Set((await query.execute()).map(({ pubkey }) => pubkey));