Improve comments and tests for inactive subscribers

[MAILPOET-4081]
This commit is contained in:
Brezo Cordero
2022-03-09 17:14:23 -06:00
committed by Veljko V
parent 6e6720d9f1
commit 5dc215efa7
2 changed files with 36 additions and 45 deletions

View File

@@ -16,7 +16,7 @@ class InactiveSubscribersController {
const UNOPENED_EMAILS_THRESHOLD = 3;
private $inactiveTaskIdsTableCreated = false;
private $processedTaskIdsTableCreated = false;
/** @var SettingsRepository */
private $settingsRepository;
@@ -79,24 +79,25 @@ class InactiveSubscribersController {
return false;
}
$inactiveTaskIdsTable = 'inactive_task_ids';
if (!$this->inactiveTaskIdsTableCreated) {
$inactiveTaskIdsTableSql = "
CREATE TEMPORARY TABLE IF NOT EXISTS {$inactiveTaskIdsTable}
// Temporary table with processed tasks from threshold date up to yesterday
$processedTaskIdsTable = 'inactive_task_ids';
if (!$this->processedTaskIdsTableCreated) {
$processedTaskIdsTableSql = "
CREATE TEMPORARY TABLE IF NOT EXISTS {$processedTaskIdsTable}
(INDEX task_id_ids (id))
SELECT DISTINCT task_id as id FROM {$sendingQueuesTable} as sq
JOIN {$scheduledTasksTable} as st ON sq.task_id = st.id
WHERE st.processed_at > :thresholdDate
AND st.processed_at < :dayAgo
";
$connection->executeQuery($inactiveTaskIdsTableSql, [
$connection->executeQuery($processedTaskIdsTableSql, [
'thresholdDate' => $thresholdDateIso,
'dayAgo' => $dayAgoIso,
]);
$this->inactiveTaskIdsTableCreated = true;
$this->processedTaskIdsTableCreated = true;
}
// Select subscribers who received at least a number of emails after threshold date
// Select subscribers who received at least a number of emails after threshold date and subscribed before that
$startId = (int)$startId;
$endId = $startId + $batchSize;
$inactiveSubscriberIdsTmpTable = 'inactive_subscriber_ids';
@@ -105,7 +106,7 @@ class InactiveSubscribersController {
(UNIQUE subscriber_id (id))
SELECT s.id FROM {$subscribersTable} as s
JOIN {$scheduledTaskSubscribersTable} as sts USE INDEX (subscriber_id) ON s.id = sts.subscriber_id
JOIN {$inactiveTaskIdsTable} task_ids ON task_ids.id = sts.task_id
JOIN {$processedTaskIdsTable} task_ids ON task_ids.id = sts.task_id
WHERE s.last_subscribed_at < :thresholdDate
AND s.status = :status
AND s.id >= :startId