refactor(getPubkeysBySearch): rename followList to followedPubkeys

This commit is contained in:
P. Reis
2024-09-18 11:26:30 -03:00
parent f73b20bf03
commit f1c0d8c18f
4 changed files with 11 additions and 11 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: new Set() }), []);
assertEquals(await getPubkeysBySearch(db.kysely, { q: 'patrick dos reis', limit: 1, followList: new Set() }), [
assertEquals(await getPubkeysBySearch(db.kysely, { q: 'pat rick', limit: 1, followedPubkeys: new Set() }), []);
assertEquals(await getPubkeysBySearch(db.kysely, { q: 'patrick dos reis', limit: 1, followedPubkeys: new Set() }), [
'47259076c85f9240e852420d7213c95e95102f1de929fb60f33a2c32570c98c4',
]);
assertEquals(await getPubkeysBySearch(db.kysely, { q: 'dosreis.com', limit: 1, followList: new Set() }), [
assertEquals(await getPubkeysBySearch(db.kysely, { q: 'dosreis.com', limit: 1, followedPubkeys: new Set() }), [
'47259076c85f9240e852420d7213c95e95102f1de929fb60f33a2c32570c98c4',
]);
});

View File

@@ -5,9 +5,9 @@ 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: Set<string> },
opts: { q: string; limit: number; followedPubkeys: Set<string> },
) {
const { q, limit, followList } = opts;
const { q, limit, followedPubkeys } = opts;
let query = kysely
.selectFrom('author_search')
@@ -22,8 +22,8 @@ export async function getPubkeysBySearch(
const pubkeys = new Set((await query.execute()).map(({ pubkey }) => pubkey));
if (followList.size > 0) {
query = query.where('pubkey', 'in', [...followList]);
if (followedPubkeys.size > 0) {
query = query.where('pubkey', 'in', [...followedPubkeys]);
}
const followingPubkeys = new Set((await query.execute()).map(({ pubkey }) => pubkey));