perf: smaller DELETE chunks for saved messages, sleep 1s between batches

This commit is contained in:
Dragory 2021-11-02 20:08:54 +02:00
parent 55a39e0758
commit d80e642cba
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1

View file

@ -1,6 +1,6 @@
import moment from "moment-timezone";
import { getRepository, In } from "typeorm";
import { DAYS, DBDateFormat, MINUTES } from "../../utils";
import { DAYS, DBDateFormat, MINUTES, SECONDS, sleep } from "../../utils";
import { connection } from "../db";
import { SavedMessage } from "../entities/SavedMessage";
@ -11,7 +11,7 @@ import { SavedMessage } from "../entities/SavedMessage";
const RETENTION_PERIOD = 1 * DAYS;
const BOT_MESSAGE_RETENTION_PERIOD = 30 * MINUTES;
const DELETED_MESSAGE_RETENTION_PERIOD = 5 * MINUTES;
const CLEAN_PER_LOOP = 200;
const CLEAN_PER_LOOP = 100;
export async function cleanupMessages(): Promise<number> {
let cleaned = 0;
@ -79,6 +79,7 @@ export async function cleanupMessages(): Promise<number> {
await messagesRepository.delete({
id: In(ids),
});
await sleep(1 * SECONDS);
}
cleaned += ids.length;