Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of statistics queries #494

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions classes/statistics_calculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ private static function get_attempt_stat_joins($cmid, $groupid, $excluderoles =
JOIN {question_references} qr ON qr.itemid = sqq.id
AND qr.component = 'mod_studentquiz'
AND qr.questionarea = 'studentquiz_question'
AND qr.usingcontextid = :contextid1
JOIN {question_bank_entries} qbe ON qr.questionbankentryid = qbe.id
JOIN {question_versions} qv ON qv.questionbankentryid = qr.questionbankentryid AND qv.version = (
SELECT MAX(version)
Expand Down Expand Up @@ -163,6 +164,7 @@ private static function get_attempt_stat_joins($cmid, $groupid, $excluderoles =
JOIN {question_references} qr ON qr.itemid = sqq.id
AND qr.component = 'mod_studentquiz'
AND qr.questionarea = 'studentquiz_question'
AND qr.usingcontextid = :contextid2
JOIN {question_bank_entries} qbe ON qr.questionbankentryid = qbe.id
JOIN {question_versions} qv ON qv.questionbankentryid = qr.questionbankentryid AND qv.version = (
SELECT MAX(version)
Expand Down Expand Up @@ -197,6 +199,7 @@ private static function get_attempt_stat_joins($cmid, $groupid, $excluderoles =
JOIN {question_references} qr ON qr.itemid = sqq.id
AND qr.component = 'mod_studentquiz'
AND qr.questionarea = 'studentquiz_question'
AND qr.usingcontextid = :contextid3
JOIN {question_bank_entries} qbe ON qr.questionbankentryid = qbe.id
JOIN {question_versions} qv ON qv.questionbankentryid = qr.questionbankentryid AND qv.version = (
SELECT MAX(version)
Expand Down Expand Up @@ -231,6 +234,7 @@ private static function get_attempt_stat_joins($cmid, $groupid, $excluderoles =
JOIN {question_references} qr ON qr.itemid = sqq.id
AND qr.component = 'mod_studentquiz'
AND qr.questionarea = 'studentquiz_question'
AND qr.usingcontextid = :contextid4
JOIN {question_bank_entries} qbe ON qr.questionbankentryid = qbe.id
JOIN {question_versions} qv ON qv.questionbankentryid = qr.questionbankentryid AND qv.version = (
SELECT MAX(version)
Expand Down Expand Up @@ -259,6 +263,7 @@ private static function get_attempt_stat_joins($cmid, $groupid, $excluderoles =
JOIN {question_references} qr ON qr.itemid = sqq.id
AND qr.component = 'mod_studentquiz'
AND qr.questionarea = 'studentquiz_question'
AND qr.usingcontextid = :contextid5
JOIN {question_bank_entries} qbe ON qr.questionbankentryid = qbe.id
JOIN {question_versions} qv ON qv.questionbankentryid = qr.questionbankentryid AND qv.version = (
SELECT MAX(version)
Expand Down Expand Up @@ -303,6 +308,7 @@ private static function get_attempt_stat_joins($cmid, $groupid, $excluderoles =
* @return array
*/
private static function get_attempt_stat_joins_params($cmid, $quantifiers = null, $userid = null): array {
$contextid = \context_module::instance($cmid)->id;
$params = [
'cmid1' => $cmid,
'cmid2' => $cmid,
Expand All @@ -311,6 +317,11 @@ private static function get_attempt_stat_joins_params($cmid, $quantifiers = null
'cmid5' => $cmid,
'cmid6' => $cmid,
'cmid7' => $cmid,
'contextid1' => $contextid,
'contextid2' => $contextid,
'contextid3' => $contextid,
'contextid4' => $contextid,
'contextid5' => $contextid,
'status1' => question_version_status::QUESTION_STATUS_HIDDEN,
'status2' => question_version_status::QUESTION_STATUS_HIDDEN,
'status3' => question_version_status::QUESTION_STATUS_HIDDEN,
Expand Down Expand Up @@ -433,6 +444,7 @@ public static function get_question_stats($cmid, $groupid) {
JOIN {question_references} qr ON qr.itemid = sqq.id
AND qr.component = 'mod_studentquiz'
AND qr.questionarea = 'studentquiz_question'
AND qr.usingcontextid = :contextid1
JOIN {question_bank_entries} qbe ON qr.questionbankentryid = qbe.id
JOIN {question_versions} qv ON qv.questionbankentryid = qr.questionbankentryid AND qv.version = (
SELECT MAX(version)
Expand All @@ -449,6 +461,7 @@ public static function get_question_stats($cmid, $groupid) {
JOIN {question_bank_entries} qbe ON qr.questionbankentryid = qbe.id
AND qr.component = 'mod_studentquiz'
AND qr.questionarea = 'studentquiz_question'
AND qr.usingcontextid = :contextid2
JOIN {question_versions} qv ON qv.questionbankentryid = qr.questionbankentryid AND qv.version = (
SELECT MAX(version)
FROM {question_versions}
Expand All @@ -464,9 +477,12 @@ public static function get_question_stats($cmid, $groupid) {
'q.parent = 0',
'sq.coursemodule = :cmid1'
];
$contextid = \context_module::instance($cmid)->id;
$params = [
'cmid1' => $cmid,
'cmid2' => $cmid,
'contextid1' => $contextid,
'contextid2' => $contextid,
'status1' => question_version_status::QUESTION_STATUS_HIDDEN,
'status2' => question_version_status::QUESTION_STATUS_HIDDEN,
];
Expand Down
Loading