Use bulk deletes for audit cleanup

This commit is contained in:
Jake Barnby 2025-03-12 16:53:08 +13:00
parent d4dd7fb757
commit 2052fb975b
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C

View file

@ -732,10 +732,12 @@ class Deletes extends Action
{
$projectId = $project->getId();
$dbForProject = $getProjectDB($project);
$audit = new Audit($dbForProject);
try {
$audit->cleanup($auditRetention);
$this->deleteByGroup(Audit::COLLECTION, [
Query::lessThan('time', $auditRetention),
Query::orderDesc('time'),
], $dbForProject);
} catch (DatabaseException $e) {
Console::error('Failed to delete audit logs for project ' . $projectId . ': ' . $e->getMessage());
}
@ -943,7 +945,7 @@ class Deletes extends Action
* @param Database $database
* @param ?callable $callback
* @return void
* @throws Exception
* @throws DatabaseException
*/
protected function deleteByGroup(
string $collection,