Speed up db:populate-extensions task

This commit is contained in:
Alex Gleason 2025-02-11 21:20:16 -06:00
parent 173aea6458
commit efbefd918a
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -1,25 +1,26 @@
import { NostrEvent } from '@nostrify/nostrify';
import { Storages } from '@/storages.ts'; import { Storages } from '@/storages.ts';
import { EventsDB } from '@/storages/EventsDB.ts'; import { EventsDB } from '@/storages/EventsDB.ts';
const store = await Storages.db();
const kysely = await Storages.kysely(); const kysely = await Storages.kysely();
for await (const msg of store.req([{}])) { const query = kysely
if (msg[0] === 'EVENT') { .selectFrom('nostr_events')
const event = msg[2]; .select(['id', 'kind', 'content', 'pubkey', 'tags', 'created_at', 'sig']);
const ext = EventsDB.indexExtensions(event); for await (const row of query.stream()) {
const event: NostrEvent = { ...row, created_at: Number(row.created_at) };
const ext = EventsDB.indexExtensions(event);
try { try {
await kysely.updateTable('nostr_events') await kysely
.set('search_ext', ext) .updateTable('nostr_events')
.where('id', '=', event.id) .set('search_ext', ext)
.execute(); .where('id', '=', event.id)
} catch { .execute();
// do nothing } catch {
} // do nothing
} else {
break;
} }
} }