When deleting old logs Delete oldest logs first

[MAILPOET-5071]
This commit is contained in:
Rostislav Wolny
2023-04-24 10:18:37 +02:00
committed by Aschepikov
parent 6f70cd1651
commit 5fa1ba823b
3 changed files with 92 additions and 1 deletions

View File

@ -70,7 +70,8 @@ class LogRepository extends Repository {
$logsTable = $this->entityManager->getClassMetadata(LogEntity::class)->getTableName();
$this->entityManager->getConnection()->executeStatement("
DELETE FROM $logsTable
WHERE `created_at` < :date LIMIT :limit
WHERE `created_at` < :date
ORDER BY `id` ASC LIMIT :limit
", [
'date' => Carbon::now()->subDays($daysToKeepLogs)->toDateTimeString(),
'limit' => $limit,