mirror of
https://github.com/aljazceru/ditto.git
synced 2025-12-17 13:34:24 +01:00
add cleanup script (apply policy to events created before it applied)
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
"hook": "deno run --allow-read --allow-run --allow-write https://deno.land/x/deno_hooks@0.1.1/mod.ts",
|
||||
"db:export": "deno run -A --env-file --deny-read=.env scripts/db-export.ts",
|
||||
"db:import": "deno run -A --env-file --deny-read=.env scripts/db-import.ts",
|
||||
"db:cleanup": "deno run -A --env-file --deny-read=.env scripts/db-policy.ts",
|
||||
"db:migrate": "deno run -A --env-file --deny-read=.env scripts/db-migrate.ts",
|
||||
"nostr:pull": "deno run -A --env-file --deny-read=.env scripts/nostr-pull.ts",
|
||||
"debug": "deno run -A --env-file --deny-read=.env --inspect src/server.ts",
|
||||
|
||||
22
scripts/db-policy.ts
Normal file
22
scripts/db-policy.ts
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user