sendou.ink/app/features/admin/AdminService.server.ts
2023-10-14 11:08:45 +03:00

37 lines
834 B
TypeScript

import { sql } from "~/db/sql";
interface AdminService {
cleanUp: () => void;
}
const removeOldLikesStm = sql.prepare(/*sql*/ `
delete from
"GroupLike"
where
"GroupLike"."createdAt" < cast(strftime('%s', datetime('now', 'start of day', '-7 days')) as int)
`);
const removeOldGroupStm = sql.prepare(/*sql*/ `
delete from
"Group"
where "Group"."id" in (
select "Group"."id"
from "Group"
left join "GroupMatch" on "Group"."id" = "GroupMatch"."alphaGroupId" or "Group"."id" = "GroupMatch"."bravoGroupId"
where "Group"."status" = 'INACTIVE'
and "GroupMatch"."id" is null
)
`);
const cleanUpStm = sql.prepare(/*sql*/ `
vacuum
`);
const cleanUp: AdminService["cleanUp"] = () => {
removeOldLikesStm.run();
removeOldGroupStm.run();
cleanUpStm.run();
};
export { cleanUp };