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

This commit is contained in:
Siddharth Singh
2024-11-17 22:17:26 +05:30
parent d2d29aef8f
commit a985d1add1
2 changed files with 23 additions and 0 deletions

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

@@ -0,0 +1,22 @@
import { policyWorker } from '@/workers/policy.ts';
import { Storages } from '@/storages.ts';
const db = await Storages.db();
const ids = [];
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);
}
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);
}