]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-9290, restore performance improvements on reading xml
authortoyomoyo <toyomoyo>
Fri, 14 Dec 2007 06:16:08 +0000 (06:16 +0000)
committertoyomoyo <toyomoyo>
Fri, 14 Dec 2007 06:16:08 +0000 (06:16 +0000)
backup/restorelib.php

index e8407d5c7f2f95a7ee1416aa2533948c366a7fae..353cb40a410725e069a081a5ff6c809fe508cdaf 100644 (file)
@@ -4083,7 +4083,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
             $this->tree[$this->level] = $tagName;
 
             //Output something to avoid browser timeouts...
-            backup_flush();
+            //backup_flush();
 
             //Check if we are into INFO zone
             //if ($this->tree[2] == "INFO")                                                             //Debug
@@ -4097,7 +4097,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
             $this->tree[$this->level] = $tagName;
 
             //Output something to avoid browser timeouts...
-            backup_flush();
+            //backup_flush();
 
             //Check if we are into INFO zone
             //if ($this->tree[2] == "INFO")                                                             //Debug
@@ -4112,7 +4112,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
             $this->tree[$this->level] = $tagName;
 
             //Output something to avoid browser timeouts...
-            backup_flush();
+            //backup_flush();
 
             //Check if we are into COURSE_HEADER zone
             //if ($this->tree[3] == "HEADER")                                                           //Debug
@@ -4126,7 +4126,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
             $this->tree[$this->level] = $tagName;
 
             //Output something to avoid browser timeouts...
-            backup_flush();
+            //backup_flush();
 
             //Check if we are into BLOCKS zone
             //if ($this->tree[3] == "BLOCKS")                                                         //Debug
@@ -4151,7 +4151,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
             $this->tree[$this->level] = $tagName;
 
             //Output something to avoid browser timeouts...
-            backup_flush();
+            //backup_flush();
 
             //Check if we are into SECTIONS zone
             //if ($this->tree[3] == "SECTIONS")                                                         //Debug
@@ -4165,7 +4165,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
             $this->tree[$this->level] = $tagName;
 
             //Output something to avoid browser timeouts...
-            backup_flush();
+            //backup_flush();
 
             //Accumulate all the data inside this tag
             if (isset($this->tree[3]) && $this->tree[3] == "FORMATDATA") {
@@ -4188,7 +4188,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
             $this->tree[$this->level] = $tagName;
 
             //Output something to avoid browser timeouts...
-            backup_flush();
+            //backup_flush();
 
             //Check if we are into METACOURSE zone
             //if ($this->tree[3] == "METACOURSE")                                                         //Debug
@@ -4203,7 +4203,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
             $this->tree[$this->level] = $tagName;
 
             //Output something to avoid browser timeouts...
-            backup_flush();
+            //backup_flush();
 
             //Check if we are into GRADEBOOK zone
             //if ($this->tree[3] == "GRADEBOOK")                                                         //Debug
@@ -4240,7 +4240,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
             $this->tree[$this->level] = $tagName;
 
             //Output something to avoid browser timeouts...
-            backup_flush();
+            //backup_flush();
 
             //Check if we are into MESSAGES zone
             //if ($this->tree[3] == "MESSAGES")                                                          //Debug
@@ -4267,7 +4267,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
             //}                                                                                        //Debug
 
             //Output something to avoid browser timeouts...
-            backup_flush();
+            //backup_flush();
 
             //Check if we are into QUESTION_CATEGORIES zone
             //if ($this->tree[3] == "QUESTION_CATEGORIES")                                              //Debug
@@ -4295,7 +4295,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
             //}                                                                                        //Debug
 
             //Output something to avoid browser timeouts...
-            backup_flush();
+            //backup_flush();
 
             //Check if we are into SCALES zone
             //if ($this->tree[3] == "SCALES")                                                           //Debug
@@ -4322,7 +4322,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
             //}                                                                                        //Debug
 
             //Output something to avoid browser timeouts...
-            backup_flush();
+            //backup_flush();
 
             //Check if we are into GROUPS zone
             //if ($this->tree[3] == "GROUPS")                                                           //Debug
@@ -4349,7 +4349,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
             //}                                                                                        //Debug
 
             //Output something to avoid browser timeouts...
-            backup_flush();
+            //backup_flush();
 
             //Check if we are into GROUPINGS zone
             //if ($this->tree[3] == "GROUPINGS")                                                           //Debug
@@ -4404,7 +4404,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
             //}                                                                                        //Debug
 
             //Output something to avoid browser timeouts...
-            backup_flush();
+            //backup_flush();
 
             //Check if we are into EVENTS zone
             //if ($this->tree[3] == "EVENTS")                                                           //Debug
@@ -4432,7 +4432,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
             //}                                                                                           //Debug
 
             //Output something to avoid browser timeouts...
-            backup_flush();
+            //backup_flush();
 
             //Check if we are into MODULES zone
             //if ($this->tree[3] == "MODULES")                                                          //Debug
@@ -4460,7 +4460,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
             //}                                                                                           //Debug
 
             //Output something to avoid browser timeouts...
-            backup_flush();
+            //backup_flush();
 
             //Check if we are into LOGS zone
             //if ($this->tree[3] == "LOGS")                                                             //Debug
@@ -4483,7 +4483,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
             $this->tree[$this->level] = $tagName;
 
             //Output something to avoid browser timeouts...
-            backup_flush();
+            //backup_flush();
 
             echo $this->level.str_repeat("&nbsp;",$this->level*2)."&lt;".$tagName."&gt;<br />\n";   //Debug
         }
@@ -6511,11 +6511,20 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
         $fp = fopen($xml_file,"r")
             or $status = false;
         if ($status) {
-            while ($data = fread($fp, 4096) and !$moodle_parser->finished)
-                    xml_parse($xml_parser, $data, feof($fp))
-                            or die(sprintf("XML error: %s at line %d",
-                            xml_error_string(xml_get_error_code($xml_parser)),
-                                    xml_get_current_line_number($xml_parser)));
+            // MDL-9290 performance improvement on reading large xml
+            $lasttime = time(); // crmas
+            while ($data = fread($fp, 4096) and !$moodle_parser->finished) {
+             
+                if ((time() - $lasttime) > 5) {
+                    $lasttime = time();
+                    backup_flush(1);
+                }
+             
+                xml_parse($xml_parser, $data, feof($fp))
+                        or die(sprintf("XML error: %s at line %d",
+                        xml_error_string(xml_get_error_code($xml_parser)),
+                                xml_get_current_line_number($xml_parser)));
+            }
             fclose($fp);
         }
         //Get info from parser