mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
delete events as they are streamed from db
This commit is contained in:
parent
a985d1add1
commit
8607810117
1 changed files with 7 additions and 10 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue