cron: delete old remote events every hour
This commit is contained in:
parent
08dd5fa4eb
commit
5d19c21f51
|
@ -1,3 +1,4 @@
|
|||
import '@/cron.ts';
|
||||
import {
|
||||
type Context,
|
||||
cors,
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
import * as eventsDB from '@/db/events.ts';
|
||||
import { cron } from '@/deps.ts';
|
||||
import { Time } from '@/utils/time.ts';
|
||||
|
||||
/** Clean up old remote events. */
|
||||
async function cleanupEvents() {
|
||||
console.log('Cleaning up old remote events...');
|
||||
|
||||
const [result] = await eventsDB.deleteFilters([{
|
||||
until: Math.floor((Date.now() - Time.days(7)) / 1000),
|
||||
local: false,
|
||||
}]);
|
||||
|
||||
console.log(`Deleted ${result?.numDeletedRows ?? 0} events.`);
|
||||
}
|
||||
|
||||
cron.hourly(cleanupEvents);
|
|
@ -156,7 +156,7 @@ async function getFilters<K extends number>(
|
|||
|
||||
/** Delete events based on filters from the database. */
|
||||
function deleteFilters<K extends number>(filters: DittoFilter<K>[]) {
|
||||
if (!filters.length) return Promise.resolve();
|
||||
if (!filters.length) return Promise.resolve([]);
|
||||
const query = getFiltersQuery(filters);
|
||||
|
||||
return db
|
||||
|
|
|
@ -65,5 +65,6 @@ export {
|
|||
} from 'npm:kysely@^0.25.0';
|
||||
export { DenoSqliteDialect } from 'https://gitlab.com/soapbox-pub/kysely-deno-sqlite/-/raw/v1.0.1/mod.ts';
|
||||
export { default as tldts } from 'npm:tldts@^6.0.14';
|
||||
export * as cron from 'https://deno.land/x/deno_cron@v1.0.0/cron.ts';
|
||||
|
||||
export type * as TypeFest from 'npm:type-fest@^4.3.0';
|
||||
|
|
Loading…
Reference in New Issue