Make db:populate:nip05 script more efficient

This commit is contained in:
Alex Gleason 2025-02-07 17:48:07 -06:00
parent 5157a90b63
commit a4a26d7575
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -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();