Use one more temp table, use better indexes for inactives sync [MAILPOET-2392]
This commit is contained in:
@@ -434,7 +434,8 @@ class Migrator {
|
|||||||
'KEY newsletter_id_subscriber_id (newsletter_id, subscriber_id),',
|
'KEY newsletter_id_subscriber_id (newsletter_id, subscriber_id),',
|
||||||
'KEY queue_id (queue_id),',
|
'KEY queue_id (queue_id),',
|
||||||
'KEY subscriber_id (subscriber_id),',
|
'KEY subscriber_id (subscriber_id),',
|
||||||
'KEY created_at (created_at)',
|
'KEY created_at (created_at),',
|
||||||
|
'KEY subscriber_id_created_at (subscriber_id, created_at)',
|
||||||
];
|
];
|
||||||
return $this->sqlify(__FUNCTION__, $attributes);
|
return $this->sqlify(__FUNCTION__, $attributes);
|
||||||
}
|
}
|
||||||
|
@@ -103,16 +103,27 @@ class InactiveSubscribersController {
|
|||||||
// Select subscribers who received a recent tracked email but didn't open it
|
// Select subscribers who received a recent tracked email but didn't open it
|
||||||
$start_id = (int)$start_id;
|
$start_id = (int)$start_id;
|
||||||
$end_id = $start_id + $batch_size;
|
$end_id = $start_id + $batch_size;
|
||||||
$ids_to_deactivate = \ORM::forTable($subscribers_table)->rawQuery("
|
$inactive_subscriber_ids_tmp_table = 'inactive_subscriber_ids';
|
||||||
SELECT s.id FROM $subscribers_table as s
|
\ORM::rawExecute("
|
||||||
JOIN $scheduled_task_subcribres_table as sts ON s.id = sts.subscriber_id
|
CREATE TEMPORARY TABLE IF NOT EXISTS $inactive_subscriber_ids_tmp_table
|
||||||
|
(UNIQUE subscriber_id (id))
|
||||||
|
SELECT DISTINCT s.id FROM $subscribers_table as s
|
||||||
|
JOIN $scheduled_task_subcribres_table as sts USE INDEX (subscriber_id) ON s.id = sts.subscriber_id
|
||||||
JOIN inactives_task_ids task_ids ON task_ids.id = sts.task_id
|
JOIN inactives_task_ids task_ids ON task_ids.id = sts.task_id
|
||||||
|
WHERE s.last_subscribed_at < ? AND s.status = ? AND s.id >= ? AND s.id < ?
|
||||||
|
LIMIT ?",
|
||||||
|
[$threshold_date_iso, Subscriber::STATUS_SUBSCRIBED, $start_id, $end_id, $batch_size]
|
||||||
|
);
|
||||||
|
|
||||||
|
$ids_to_deactivate = \ORM::forTable($inactive_subscriber_ids_tmp_table)->rawQuery("
|
||||||
|
SELECT s.id FROM $inactive_subscriber_ids_tmp_table s
|
||||||
LEFT OUTER JOIN $statistics_opens_table as so ON s.id = so.subscriber_id AND so.created_at > ?
|
LEFT OUTER JOIN $statistics_opens_table as so ON s.id = so.subscriber_id AND so.created_at > ?
|
||||||
WHERE s.last_subscribed_at < ? AND s.status = ? AND so.id IS NULL AND s.id >= ? AND s.id < ?
|
WHERE so.id IS NULL",
|
||||||
GROUP BY s.id LIMIT ?",
|
[$threshold_date_iso]
|
||||||
[$threshold_date_iso, $threshold_date_iso, Subscriber::STATUS_SUBSCRIBED, $start_id, $end_id, $batch_size]
|
|
||||||
)->findArray();
|
)->findArray();
|
||||||
|
|
||||||
|
\ORM::rawExecute("DROP TABLE $inactive_subscriber_ids_tmp_table");
|
||||||
|
|
||||||
$ids_to_deactivate = array_map(
|
$ids_to_deactivate = array_map(
|
||||||
function ($id) {
|
function ($id) {
|
||||||
return (int)$id['id'];
|
return (int)$id['id'];
|
||||||
|
Reference in New Issue
Block a user