refactor: make getPubkeysBySearch() function use set of strings Set<string>

This commit is contained in:
P. Reis
2024-09-17 14:50:33 -03:00
parent 47c1d290b0
commit f73b20bf03
4 changed files with 8 additions and 14 deletions

View File

@@ -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',
]);
});

View File

@@ -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<DittoTables>,
opts: { q: string; limit: number; followList: string[] },
opts: { q: string; limit: number; followList: Set<string> },
) {
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));