diff --git a/backend/src/plugins/Utility/commands/CleanCmd.ts b/backend/src/plugins/Utility/commands/CleanCmd.ts index 6abbb481..2b812da8 100644 --- a/backend/src/plugins/Utility/commands/CleanCmd.ts +++ b/backend/src/plugins/Utility/commands/CleanCmd.ts @@ -6,12 +6,12 @@ import { LogType } from "../../../data/LogType"; import { ModActionsPlugin } from "../../../plugins/ModActions/ModActionsPlugin"; import { getBaseUrl, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { allowTimeout } from "../../../RegExpRunner"; -import { DAYS, getInviteCodesInString, noop, SECONDS } from "../../../utils"; +import { chunkArray, DAYS, getInviteCodesInString, noop, SECONDS } from "../../../utils"; import { utilityCmd, UtilityPluginType } from "../types"; import { LogsPlugin } from "../../Logs/LogsPlugin"; import { humanizeDurationShort } from "../../../humanizeDurationShort"; -const MAX_CLEAN_COUNT = 150; +const MAX_CLEAN_COUNT = 300; const MAX_CLEAN_TIME = 1 * DAYS; const MAX_CLEAN_API_REQUESTS = 20; const CLEAN_COMMAND_DELETE_DELAY = 10 * SECONDS; @@ -33,9 +33,15 @@ export async function cleanMessages( idsToDelete.forEach((id) => pluginData.state.logs.ignoreLog(LogType.MESSAGE_DELETE, id)); pluginData.state.logs.ignoreLog(LogType.MESSAGE_DELETE_BULK, idsToDelete[0]); - // Actually delete the messages - channel.bulkDelete(idsToDelete); - await pluginData.state.savedMessages.markBulkAsDeleted(idsToDelete); + // Actually delete the messages (in chunks of 100) + + const chunks = chunkArray(idsToDelete, 100); + await Promise.all( + chunks.map(async (chunk) => { + await channel.bulkDelete(chunk); + await pluginData.state.savedMessages.markBulkAsDeleted(chunk); + }), + ); // Create an archive const archiveId = await pluginData.state.archives.createFromSavedMessages(savedMessages, pluginData.guild);