-
Bug
-
Resolution: Fixed
-
Minor
-
3.8, 3.9.1, 3.10
-
MOODLE_310_STABLE, MOODLE_38_STABLE, MOODLE_39_STABLE
-
MOODLE_38_STABLE, MOODLE_39_STABLE
-
master_
MDL-67440 -
The following part of the clean up task seems to take hours on my local machine running postgres (it's not optimised well - but we're also seeing this take ages on prod server as well.)
https://github.com/moodle/moodle/blob/master/analytics/classes/manager.php#L628
$DB->delete_records_select('analytics_predictions', "contextid NOT IN ($contextsql)"); |
$DB->delete_records_select('analytics_indicator_calc', "contextid NOT IN ($contextsql)"); |
Changing it to use a join makes it run in less than a second
- $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)"); |
+ $DB->execute("DELETE FROM {analytics_predictions} WHERE id IN (
|
+ SELECT p.id
|
+ FROM {analytics_predictions} p
|
+ LEFT JOIN {context} ctx ON p.contextid = ctx.id
|
+ WHERE ctx.id IS NULL
|
+ )");
|
+
|
+ $DB->execute("DELETE FROM {analytics_indicator_calc} WHERE id IN (
|
+ SELECT c.id
|
+ FROM {analytics_indicator_calc} c
|
+ LEFT JOIN {context} ctx ON c.contextid = ctx.id
|
+ WHERE ctx.id IS NULL
|
+ )");
|
Haven't tested on mysql/other dbs sorry!
- has a non-specific relationship to
-
MDL-66498 Analytics cleanup() causes error for large moodle installations under postgres
- Closed