Merge branch 'ditto-retroactive-policies' into 'main'

add cleanup script (apply policy to events created before it applied)

Closes #232

See merge request soapbox-pub/ditto!590
This commit is contained in:
Alex Gleason
2024-11-21 16:37:57 +00:00
2 changed files with 20 additions and 0 deletions

19
scripts/db-policy.ts Normal file
View File

@@ -0,0 +1,19 @@
import { policyWorker } from '@/workers/policy.ts';
import { Storages } from '@/storages.ts';
const db = await Storages.db();
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) {
await db.remove([{ ids: [event.id] }]);
count += 1;
}
}
console.log(`Cleaned up ${count} events from the db.`);
Deno.exit(0);