Retain bot messages for a shorter time, raise deletion limit

This commit is contained in:
Dragory 2020-05-28 02:50:07 +03:00
parent 6cd07ed696
commit 26f1042b8e
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1

View file

@ -14,6 +14,7 @@ const CLEANUP_INTERVAL = 5 * MINUTES;
* This is very heavy storage-wise, so keeping it as low as possible is ideal. * This is very heavy storage-wise, so keeping it as low as possible is ideal.
*/ */
const RETENTION_PERIOD = 1 * DAYS; const RETENTION_PERIOD = 1 * DAYS;
const BOT_MESSAGE_RETENTION_PERIOD = 30 * MINUTES;
async function cleanup() { async function cleanup() {
const repository = getRepository(SavedMessage); const repository = getRepository(SavedMessage);
@ -29,11 +30,19 @@ async function cleanup() {
.orWhere( .orWhere(
// Clear old messages // Clear old messages
new Brackets(qb => { new Brackets(qb => {
qb.where("is_permanent = 0"); qb.where(`posted_at <= (NOW() - INTERVAL ${RETENTION_PERIOD}000 MICROSECOND)`);
qb.andWhere(`posted_at <= (NOW() - INTERVAL ${RETENTION_PERIOD}000 MICROSECOND)`); qb.andWhere("is_permanent = 0");
}), }),
) )
.limit(50_000) // To avoid long table locks, limit the amount of messages deleted at once .orWhere(
// Clear old bot messages
new Brackets(qb => {
qb.where("is_bot = 1");
qb.andWhere(`posted_at <= (NOW() - INTERVAL ${BOT_MESSAGE_RETENTION_PERIOD}000 MICROSECOND)`);
qb.andWhere("is_permanent = 0");
}),
)
.limit(100_000) // To avoid long table locks, limit the amount of messages deleted at once
.delete() .delete()
.execute(); .execute();