mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Speed up db:populate-extensions task
This commit is contained in:
parent
173aea6458
commit
efbefd918a
1 changed files with 16 additions and 15 deletions
|
|
@ -1,26 +1,27 @@
|
|||
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']);
|
||||
|
||||
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')
|
||||
await kysely
|
||||
.updateTable('nostr_events')
|
||||
.set('search_ext', ext)
|
||||
.where('id', '=', event.id)
|
||||
.execute();
|
||||
} catch {
|
||||
// do nothing
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Deno.exit();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue