mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Add semaphore to nip05 script
This commit is contained in:
parent
b902abc7cc
commit
7780507a15
1 changed files with 30 additions and 22 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { Semaphore } from '@lambdalisue/async';
|
||||||
import { NSchema as n } from '@nostrify/nostrify';
|
import { NSchema as n } from '@nostrify/nostrify';
|
||||||
|
|
||||||
import { Storages } from '@/storages.ts';
|
import { Storages } from '@/storages.ts';
|
||||||
|
|
@ -5,6 +6,7 @@ import { faviconCache } from '@/utils/favicon.ts';
|
||||||
import { nip05Cache } from '@/utils/nip05.ts';
|
import { nip05Cache } from '@/utils/nip05.ts';
|
||||||
|
|
||||||
const kysely = await Storages.kysely();
|
const kysely = await Storages.kysely();
|
||||||
|
const sem = new Semaphore(5);
|
||||||
|
|
||||||
const query = kysely
|
const query = kysely
|
||||||
.selectFrom('nostr_events')
|
.selectFrom('nostr_events')
|
||||||
|
|
@ -12,11 +14,16 @@ const query = kysely
|
||||||
.where('kind', '=', 0);
|
.where('kind', '=', 0);
|
||||||
|
|
||||||
for await (const { content } of query.stream(100)) {
|
for await (const { content } of query.stream(100)) {
|
||||||
|
while (sem.locked) {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
sem.lock(async () => {
|
||||||
const signal = AbortSignal.timeout(30_000); // generous timeout
|
const signal = AbortSignal.timeout(30_000); // generous timeout
|
||||||
|
|
||||||
// Parse metadata.
|
// Parse metadata.
|
||||||
const metadata = n.json().pipe(n.metadata()).catch({}).safeParse(content);
|
const metadata = n.json().pipe(n.metadata()).catch({}).safeParse(content);
|
||||||
if (!metadata.success) continue;
|
if (!metadata.success) return;
|
||||||
|
|
||||||
// Update nip05.
|
// Update nip05.
|
||||||
const { nip05 } = metadata.data;
|
const { nip05 } = metadata.data;
|
||||||
|
|
@ -37,6 +44,7 @@ for await (const { content } of query.stream(100)) {
|
||||||
// Ignore.
|
// Ignore.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Deno.exit();
|
Deno.exit();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue