mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Make db:populate:nip05 script more efficient
This commit is contained in:
parent
5157a90b63
commit
a4a26d7575
1 changed files with 24 additions and 29 deletions
|
|
@ -5,21 +5,15 @@ import { faviconCache } from '@/utils/favicon.ts';
|
||||||
import { nip05Cache } from '@/utils/nip05.ts';
|
import { nip05Cache } from '@/utils/nip05.ts';
|
||||||
|
|
||||||
const store = await Storages.db();
|
const store = await Storages.db();
|
||||||
const kysely = await Storages.kysely();
|
|
||||||
const statsQuery = kysely.selectFrom('author_stats').select('pubkey');
|
|
||||||
|
|
||||||
for await (const { pubkey } of statsQuery.stream(10)) {
|
for await (const msg of store.req([{ kinds: [0] }])) {
|
||||||
|
if (msg[0] === 'EVENT') {
|
||||||
const signal = AbortSignal.timeout(30_000); // generous timeout
|
const signal = AbortSignal.timeout(30_000); // generous timeout
|
||||||
|
const event = msg[2];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const [author] = await store.query([{ kinds: [0], authors: [pubkey], limit: 1 }]);
|
|
||||||
|
|
||||||
if (!author) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse metadata.
|
// Parse metadata.
|
||||||
const metadata = n.json().pipe(n.metadata()).catch({}).safeParse(author.content);
|
const metadata = n.json().pipe(n.metadata()).catch({}).safeParse(event.content);
|
||||||
if (!metadata.success) continue;
|
if (!metadata.success) continue;
|
||||||
|
|
||||||
// Update nip05.
|
// Update nip05.
|
||||||
|
|
@ -40,6 +34,7 @@ for await (const { pubkey } of statsQuery.stream(10)) {
|
||||||
} catch {
|
} catch {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Deno.exit();
|
Deno.exit();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue