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,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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue