]> git.mjollnir.org Git - moodle.git/commitdiff
quiz: MDL-17873 small efficiency gains.
authortjhunt <tjhunt>
Wed, 11 Feb 2009 07:52:26 +0000 (07:52 +0000)
committertjhunt <tjhunt>
Wed, 11 Feb 2009 07:52:26 +0000 (07:52 +0000)
mod/quiz/edit.php
mod/quiz/editlib.php

index bb60aab447927ff477433cebdadb97f26b95907e..9453c28b9822218c80a7517cae5bd0c979c3d9ab 100644 (file)
@@ -274,13 +274,13 @@ if ((optional_param('addrandom', false, PARAM_BOOL) OR $newrandomcategory)
     // Find existing random questions in this category that are
     // not used by any quiz.
     if ($existingquestions = $DB->get_records_sql(
-            "SELECT * FROM {question} q
+            "SELECT q.id,q.qtype FROM {question} q
             WHERE qtype = '" . RANDOM . "'
                 AND category = ?
                 AND " . $DB->sql_compare_text('questiontext') . " = ?
                 AND NOT EXISTS (SELECT * FROM {quiz_question_instances} WHERE question = q.id)
             ORDER BY id", array($category->id, $recurse))) {
-    // Take as many of these as needed.
+        // Take as many of these as needed.
         while (($existingquestion = array_shift($existingquestions))
                 and $randomcount > 0) {
             quiz_add_quiz_question($existingquestion->id, $quiz, $addonpage);
index 6937d5ce0f8b7eb9b394639990c6a287c4a66c81..f5f936f38ff210b4188ce5938abd71337b80e585 100644 (file)
@@ -133,9 +133,7 @@ function quiz_add_quiz_question($id, &$quiz, $page=0) {
     }
 
     // update question grades
-    $questionrecord = $DB->get_record('question', array('id' => $id));
-    $quiz->grades[$id]
-            = $questionrecord->defaultgrade;
+    $quiz->grades[$id] = $DB->get_field('question', 'defaultgrade', array('id' => $id));
     quiz_update_question_instance($quiz->grades[$id], $id, $quiz->instance);
 
     return true;
@@ -683,17 +681,8 @@ function quiz_simple_question_list($pageurl, $categorylist, $numbertoshow=3,
     $categorylist_array =  explode(',', $categorylist);
     list($usql, $params) = $DB->get_in_or_equal($categorylist_array);
 
-    if (!$questions = $DB->get_records_select('question',
-            "category $usql AND parent = '0' $showhidden",
-            $params, $sortorderdecoded, '*', 0, $numbertoshow)) {
-        // There are no questions on the requested page.
-        $page = 0;
-        if (!$questions = $DB->get_records_select('question',
-                "category $usql AND parent = '0' $showhidden",
-                $params, $sortorderdecoded, '*', 0, $numbertoshow)) {
-            // There are no questions at all
-            return;
-        }
+    if (!$questions = $DB->get_records_select('question', "category $usql AND parent = '0' $showhidden",
+            $params, $sortorderdecoded, 'qtype,name,questiontext,questiontextformat', 0, $numbertoshow)) {
     }
     foreach ($questions as $question) {
         echo "<li>";