Skip to content

Commit

Permalink
MDL-67440 analytics: optimse delete's in clean up task.
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-catalyst authored and danmarsden committed Jul 7, 2020
1 parent 49a9e8b commit 7f55289
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions analytics/classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,9 +624,25 @@ public static function cleanup() {
LEFT JOIN {context} ctx ON ap.contextid = ctx.id
WHERE ctx.id IS NULL)");

$contextsql = "SELECT id FROM {context} ctx";
$DB->delete_records_select('analytics_predictions', "contextid NOT IN ($contextsql)");
$DB->delete_records_select('analytics_indicator_calc', "contextid NOT IN ($contextsql)");
// Cleanup analaytics predictions/calcs with MySQL friendly sub-select.
$DB->execute("DELETE FROM {analytics_predictions} WHERE id IN (
SELECT oldpredictions.id
FROM (
SELECT p.id
FROM {analytics_predictions} p
LEFT JOIN {context} ctx ON p.contextid = ctx.id
WHERE ctx.id IS NULL
) oldpredictions
)");

$DB->execute("DELETE FROM {analytics_indicator_calc} WHERE id IN (
SELECT oldcalcs.id FROM (
SELECT c.id
FROM {analytics_indicator_calc} c
LEFT JOIN {context} ctx ON c.contextid = ctx.id
WHERE ctx.id IS NULL
) oldcalcs
)");

// Clean up stuff that depends on analysable ids that do not exist anymore.

Expand Down

0 comments on commit 7f55289

Please sign in to comment.