sendou.ink/app/features/admin/AdminService.server.ts
Kalle 24875c1fb4
SendouQ real(er) time with notifications (#1525)
* Initial

* Move code

* More events implemented

* Auto refresh take in account recent revalidates

* Add sound effects

* Add creds

* Settings

* Add error handling

* Add envs
2023-10-18 18:33:17 +03:00

35 lines
820 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
`);
export const cleanUp: AdminService["cleanUp"] = () => {
removeOldLikesStm.run();
removeOldGroupStm.run();
cleanUpStm.run();
};