mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-06-03 06:35:42 -05:00
37 lines
834 B
TypeScript
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 };
|