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 { EventsDB } from '@/storages/EventsDB.ts';
const store = await Storages.db();
const kysely = await Storages.kysely();
for await (const msg of store.req([{}])) {
if (msg[0] === 'EVENT') {
const event = msg[2];
const query = kysely
.selectFrom('nostr_events')
.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 {
await kysely.updateTable('nostr_events')
.set('search_ext', ext)
.where('id', '=', event.id)
.execute();
} catch {
// do nothing
}
} else {
break;
try {
await kysely
.updateTable('nostr_events')
.set('search_ext', ext)
.where('id', '=', event.id)
.execute();
} catch {
// do nothing
}
}