From: tjhunt Date: Wed, 11 Feb 2009 07:52:26 +0000 (+0000) Subject: quiz: MDL-17873 small efficiency gains. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=ad65ff47d876c78b6aa8e038330b8b8edc108c0c;p=moodle.git quiz: MDL-17873 small efficiency gains. --- diff --git a/mod/quiz/edit.php b/mod/quiz/edit.php index bb60aab447..9453c28b98 100644 --- a/mod/quiz/edit.php +++ b/mod/quiz/edit.php @@ -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); diff --git a/mod/quiz/editlib.php b/mod/quiz/editlib.php index 6937d5ce0f..f5f936f38f 100644 --- a/mod/quiz/editlib.php +++ b/mod/quiz/editlib.php @@ -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 "
  • ";