mirror of
https://github.com/aljazceru/ditto.git
synced 2025-12-17 05:24:22 +01:00
delete events as they are streamed from db
This commit is contained in:
@@ -2,21 +2,18 @@ import { policyWorker } from '@/workers/policy.ts';
|
||||
import { Storages } from '@/storages.ts';
|
||||
|
||||
const db = await Storages.db();
|
||||
const ids = [];
|
||||
let count = 0;
|
||||
|
||||
for await (const msg of db.req([{}])) {
|
||||
const [type, , event] = msg;
|
||||
if (type === 'EOSE') console.log('EOSE');
|
||||
if (type !== 'EVENT') continue;
|
||||
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 {
|
||||
await db.remove([{ ids }]);
|
||||
console.log(`Cleaned up ${ids.length} events from the db.`);
|
||||
Deno.exit(0);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
Deno.exit(1);
|
||||
}
|
||||
console.log(`Cleaned up ${count} events from the db.`);
|
||||
Deno.exit(0);
|
||||
|
||||
Reference in New Issue
Block a user