Limit rows deleted from mailpoet_logs in on run of purge routine
The probability of the routine to run is 5% so it should run approximately 5 times per 100 writes. So the limit 1000 should be pretty safe to prevent the table from bloating. [MAILPOET-5071]
This commit is contained in:
committed by
Aschepikov
parent
bcee2abb2c
commit
6f70cd1651
@ -13,6 +13,11 @@ class LogHandler extends AbstractProcessingHandler {
|
|||||||
*/
|
*/
|
||||||
const DAYS_TO_KEEP_LOGS = 30;
|
const DAYS_TO_KEEP_LOGS = 30;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How many records to delete on one run of purge routine
|
||||||
|
*/
|
||||||
|
const PURGE_LIMIT = 1000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Percentage value, what is the probability of running purge routine
|
* Percentage value, what is the probability of running purge routine
|
||||||
* @var int
|
* @var int
|
||||||
@ -76,6 +81,6 @@ class LogHandler extends AbstractProcessingHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function purgeOldLogs() {
|
private function purgeOldLogs() {
|
||||||
$this->logRepository->purgeOldLogs(self::DAYS_TO_KEEP_LOGS);
|
$this->logRepository->purgeOldLogs(self::DAYS_TO_KEEP_LOGS, self::PURGE_LIMIT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ use MailPoet\Entities\LogEntity;
|
|||||||
use MailPoet\Entities\NewsletterEntity;
|
use MailPoet\Entities\NewsletterEntity;
|
||||||
use MailPoet\Util\Helpers;
|
use MailPoet\Util\Helpers;
|
||||||
use MailPoetVendor\Carbon\Carbon;
|
use MailPoetVendor\Carbon\Carbon;
|
||||||
|
use MailPoetVendor\Doctrine\DBAL\Driver\PDO\Connection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @extends Repository<LogEntity>
|
* @extends Repository<LogEntity>
|
||||||
@ -65,12 +66,19 @@ class LogRepository extends Repository {
|
|||||||
return $query->getQuery()->getResult();
|
return $query->getQuery()->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function purgeOldLogs(int $daysToKeepLogs) {
|
public function purgeOldLogs(int $daysToKeepLogs, int $limit = 1000) {
|
||||||
$queryBuilder = $this->entityManager->createQueryBuilder();
|
$logsTable = $this->entityManager->getClassMetadata(LogEntity::class)->getTableName();
|
||||||
return $queryBuilder->delete(LogEntity::class, 'l')
|
$this->entityManager->getConnection()->executeStatement("
|
||||||
->where('l.createdAt < :days')
|
DELETE FROM $logsTable
|
||||||
->setParameter('days', Carbon::now()->subDays($daysToKeepLogs)->toDateTimeString())
|
WHERE `created_at` < :date LIMIT :limit
|
||||||
->getQuery()->execute();
|
", [
|
||||||
|
'date' => Carbon::now()->subDays($daysToKeepLogs)->toDateTimeString(),
|
||||||
|
'limit' => $limit,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'date' => Connection::PARAM_STR,
|
||||||
|
'limit' => Connection::PARAM_INT,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRawMessagesForNewsletter(NewsletterEntity $newsletter, string $topic): array {
|
public function getRawMessagesForNewsletter(NewsletterEntity $newsletter, string $topic): array {
|
||||||
|
Reference in New Issue
Block a user