mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-18 12:54:24 +01:00
refactor: make getPubkeysBySearch() function use set of strings Set<string>
This commit is contained in:
@@ -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',
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user