mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
refactor: make getPubkeysBySearch() function use set of strings Set<string>
This commit is contained in:
parent
47c1d290b0
commit
f73b20bf03
4 changed files with 8 additions and 14 deletions
|
|
@ -136,10 +136,7 @@ const accountSearchController: AppController = async (c) => {
|
||||||
return c.json(pubkey ? [await accountFromPubkey(pubkey)] : []);
|
return c.json(pubkey ? [await accountFromPubkey(pubkey)] : []);
|
||||||
}
|
}
|
||||||
|
|
||||||
const followList: string[] = [];
|
const followList: Set<string> = viewerPubkey ? await getFollowedPubkeys(viewerPubkey) : new Set();
|
||||||
if (viewerPubkey) {
|
|
||||||
followList.push(...await getFollowedPubkeys(viewerPubkey));
|
|
||||||
}
|
|
||||||
const pubkeys = (await getPubkeysBySearch(kysely, { q: query, limit, followList })).slice(0, limit);
|
const pubkeys = (await getPubkeysBySearch(kysely, { q: query, limit, followList })).slice(0, limit);
|
||||||
|
|
||||||
let events = event ? [event] : await store.query([{ kinds: [0], authors: pubkeys, limit }], {
|
let events = event ? [event] : await store.query([{ kinds: [0], authors: pubkeys, limit }], {
|
||||||
|
|
|
||||||
|
|
@ -96,10 +96,7 @@ async function searchEvents(
|
||||||
if (type === 'accounts') {
|
if (type === 'accounts') {
|
||||||
const kysely = await Storages.kysely();
|
const kysely = await Storages.kysely();
|
||||||
|
|
||||||
const followList: string[] = [];
|
const followList: Set<string> = viewerPubkey ? await getFollowedPubkeys(viewerPubkey) : new Set();
|
||||||
if (viewerPubkey) {
|
|
||||||
followList.push(...await getFollowedPubkeys(viewerPubkey));
|
|
||||||
}
|
|
||||||
pubkeys.push(...(await getPubkeysBySearch(kysely, { q, limit, followList })));
|
pubkeys.push(...(await getPubkeysBySearch(kysely, { q, limit, followList })));
|
||||||
|
|
||||||
if (!filter?.authors) {
|
if (!filter?.authors) {
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,11 @@ Deno.test('fuzzy search works', async () => {
|
||||||
search: 'patrickReiis patrickdosreis.com',
|
search: 'patrickReiis patrickdosreis.com',
|
||||||
}).execute();
|
}).execute();
|
||||||
|
|
||||||
assertEquals(await getPubkeysBySearch(db.kysely, { q: 'pat rick', 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: [] }), [
|
assertEquals(await getPubkeysBySearch(db.kysely, { q: 'patrick dos reis', limit: 1, followList: new Set() }), [
|
||||||
'47259076c85f9240e852420d7213c95e95102f1de929fb60f33a2c32570c98c4',
|
'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',
|
'47259076c85f9240e852420d7213c95e95102f1de929fb60f33a2c32570c98c4',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { DittoTables } from '@/db/DittoTables.ts';
|
||||||
/** Get pubkeys whose name and NIP-05 is similar to 'q' */
|
/** Get pubkeys whose name and NIP-05 is similar to 'q' */
|
||||||
export async function getPubkeysBySearch(
|
export async function getPubkeysBySearch(
|
||||||
kysely: Kysely<DittoTables>,
|
kysely: Kysely<DittoTables>,
|
||||||
opts: { q: string; limit: number; followList: string[] },
|
opts: { q: string; limit: number; followList: Set<string> },
|
||||||
) {
|
) {
|
||||||
const { q, limit, followList } = opts;
|
const { q, limit, followList } = opts;
|
||||||
|
|
||||||
|
|
@ -22,8 +22,8 @@ export async function getPubkeysBySearch(
|
||||||
|
|
||||||
const pubkeys = new Set((await query.execute()).map(({ pubkey }) => pubkey));
|
const pubkeys = new Set((await query.execute()).map(({ pubkey }) => pubkey));
|
||||||
|
|
||||||
if (followList.length > 0) {
|
if (followList.size > 0) {
|
||||||
query = query.where('pubkey', 'in', followList);
|
query = query.where('pubkey', 'in', [...followList]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const followingPubkeys = new Set((await query.execute()).map(({ pubkey }) => pubkey));
|
const followingPubkeys = new Set((await query.execute()).map(({ pubkey }) => pubkey));
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue