Skip to content

Commit

Permalink
Use set over array
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed Jan 13, 2024
1 parent fe6caf7 commit bc8f226
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/routes/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,12 @@ function GlobalSearch(props: {
foundNpubs: (string | undefined)[];
}) {
const hexpubs = createMemo(() => {
const hexpubs: string[] = [];
const hexpubs: Set<string> = new Set();
for (const npub of props.foundNpubs) {
hexpubFromNpub(npub)
.then((h) => {
if (h) {
hexpubs.push(h);
hexpubs.add(h);
}
})
.catch((e) => {
Expand All @@ -361,7 +361,7 @@ function GlobalSearch(props: {
return hexpubs;
});

async function searchFetcher(args: { value?: string; hexpubs?: string[] }) {
async function searchFetcher(args: { value?: string; hexpubs?: Set<string> }) {
try {
// Handling case when value starts with "npub"
if (args.value?.toLowerCase().startsWith("npub")) {
Expand All @@ -377,7 +377,7 @@ function GlobalSearch(props: {

// Handling case for other values (name, nip-05, whatever else primal searches)
const contacts = await searchProfiles(args.value!.toLowerCase());
return contacts.filter((c) => !args.hexpubs?.includes(c.hexpub));
return contacts.filter((c) => !args.hexpubs?.has(c.hexpub));
} catch (e) {
console.error(e);
return [];
Expand Down

0 comments on commit bc8f226

Please sign in to comment.