Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-40584 backup: Query db once per category in precheck

The cache is function local and testing against a large database
indicates 10k questions is a large category.  Restore already
uses MEMORY_EXTRA and that will have enough space for the couple
of megabtyes a local sql hash will introduce.
  • Loading branch information...
commit d51121efbe11b8bf1d8092a023cc2216f00ed13f 1 parent c2ad901
@mr-russ mr-russ authored
Showing with 13 additions and 6 deletions.
  1. +13 −6 backup/util/dbops/restore_dbops.class.php
View
19 backup/util/dbops/restore_dbops.class.php
@@ -614,13 +614,20 @@ public static function prechek_precheck_qbanks_by_level($restoreid, $courseid, $
} else {
self::set_backup_ids_record($restoreid, 'question_category', $category->id, $matchcat->id, $targetcontext->id);
$questions = self::restore_get_questions($restoreid, $category->id);
+
+ // Collect all the questions for this category into memory so we only talk to the DB once.
+ $questioncache = $DB->get_records_sql_menu("SELECT ".$DB->sql_concat('stamp', "' '", 'version').", id
+ FROM {question}
+ WHERE category = ?", array($matchcat->id));
+
foreach ($questions as $question) {
- $matchq = $DB->get_record('question', array(
- 'category' => $matchcat->id,
- 'stamp' => $question->stamp,
- 'version' => $question->version));
+ if (isset($questioncache[$question->stamp." ".$question->version])) {
+ $matchqid = $questioncache[$question->stamp." ".$question->version];
+ } else {
+ $matchqid = false;
+ }
// 5a) No match, check if user can add q
- if (!$matchq) {
+ if (!$matchqid) {
// 6a) User can, mark the q to be created
if ($canadd) {
// Nothing to mark, newitemid means create
@@ -645,7 +652,7 @@ public static function prechek_precheck_qbanks_by_level($restoreid, $courseid, $
// 5b) Match, mark q to be mapped
} else {
- self::set_backup_ids_record($restoreid, 'question', $question->id, $matchq->id);
+ self::set_backup_ids_record($restoreid, 'question', $question->id, $matchqid);
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.