mirror of
https://github.com/aljazceru/ditto.git
synced 2025-12-17 13:34:24 +01:00
refactor: insert each event per iteration in for loop - db:populate-search
This commit is contained in:
@@ -1,12 +1,9 @@
|
|||||||
import { NSchema as n } from '@nostrify/nostrify';
|
import { NSchema as n } from '@nostrify/nostrify';
|
||||||
import { Storages } from '@/storages.ts';
|
import { Storages } from '@/storages.ts';
|
||||||
import { DittoTables } from '@/db/DittoTables.ts';
|
|
||||||
|
|
||||||
const store = await Storages.db();
|
const store = await Storages.db();
|
||||||
const kysely = await Storages.kysely();
|
const kysely = await Storages.kysely();
|
||||||
|
|
||||||
const values: DittoTables['author_search'][] = [];
|
|
||||||
|
|
||||||
for await (const msg of store.req([{ kinds: [0] }])) {
|
for await (const msg of store.req([{ kinds: [0] }])) {
|
||||||
if (msg[0] === 'EVENT') {
|
if (msg[0] === 'EVENT') {
|
||||||
const { pubkey, content } = msg[2];
|
const { pubkey, content } = msg[2];
|
||||||
@@ -14,15 +11,11 @@ for await (const msg of store.req([{ kinds: [0] }])) {
|
|||||||
const { name, nip05 } = n.json().pipe(n.metadata()).catch({}).parse(content);
|
const { name, nip05 } = n.json().pipe(n.metadata()).catch({}).parse(content);
|
||||||
const search = [name, nip05].filter(Boolean).join(' ').trim();
|
const search = [name, nip05].filter(Boolean).join(' ').trim();
|
||||||
|
|
||||||
values.push({
|
|
||||||
pubkey: pubkey,
|
|
||||||
search,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await kysely.insertInto('author_search').values(values).onConflict(
|
await kysely.insertInto('author_search').values({
|
||||||
|
pubkey,
|
||||||
|
search,
|
||||||
|
}).onConflict(
|
||||||
(oc) =>
|
(oc) =>
|
||||||
oc.column('pubkey')
|
oc.column('pubkey')
|
||||||
.doUpdateSet((eb) => ({ search: eb.ref('excluded.search') })),
|
.doUpdateSet((eb) => ({ search: eb.ref('excluded.search') })),
|
||||||
@@ -31,5 +24,9 @@ try {
|
|||||||
} catch {
|
} catch {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Deno.exit();
|
Deno.exit();
|
||||||
|
|||||||
Reference in New Issue
Block a user