delete events as they are streamed from db

This commit is contained in:
Siddharth Singh 2024-11-21 22:03:55 +05:30
parent a985d1add1
commit 8607810117
No known key found for this signature in database

View file

@ -2,21 +2,18 @@ import { policyWorker } from '@/workers/policy.ts';
import { Storages } from '@/storages.ts'; import { Storages } from '@/storages.ts';
const db = await Storages.db(); const db = await Storages.db();
const ids = []; let count = 0;
for await (const msg of db.req([{}])) { for await (const msg of db.req([{}])) {
const [type, , event] = msg; const [type, , event] = msg;
if (type === 'EOSE') console.log('EOSE'); if (type === 'EOSE') console.log('EOSE');
if (type !== 'EVENT') continue; if (type !== 'EVENT') continue;
const [, , ok] = await policyWorker.call(event, AbortSignal.timeout(5000)); const [, , ok] = await policyWorker.call(event, AbortSignal.timeout(5000));
if (!ok) ids.push(event.id); if (!ok) {
await db.remove([{ ids: [event.id] }]);
count += 1;
}
} }
try { console.log(`Cleaned up ${count} events from the db.`);
await db.remove([{ ids }]);
console.log(`Cleaned up ${ids.length} events from the db.`);
Deno.exit(0); Deno.exit(0);
} catch (e) {
console.error(e);
Deno.exit(1);
}