summaryrefslogtreecommitdiff
path: root/modules/gallery
diff options
context:
space:
mode:
authorshadlaws <shad@shadlaws.com>2013-05-15 11:16:46 +0200
committershadlaws <shad@shadlaws.com>2013-05-15 11:16:46 +0200
commit6f922ca427ff94937904979d02e6fba063effd77 (patch)
treecbf9a8f5ada4ee39cb225bf43f19b197b1fbe6be /modules/gallery
parent666f3a30e2e7ad620d50740d76364eac1c23053b (diff)
Follow-on to #2069 - Decrease stack size of MPTT rebuild task.
This reduces the likelihood that we'll hit a limit with gargantuan galleries. --HG-- extra : source : c4a118d43145a2a4ec9b934d3aebe8f9458bcf07
Diffstat (limited to 'modules/gallery')
-rw-r--r--modules/gallery/helpers/gallery_task.php70
1 files changed, 36 insertions, 34 deletions
diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php
index ac98831b..618cf8fd 100644
--- a/modules/gallery/helpers/gallery_task.php
+++ b/modules/gallery/helpers/gallery_task.php
@@ -398,48 +398,50 @@ class gallery_task_Core {
switch ($state) {
case self::FIX_STATE_START_MPTT:
$task->set("ptr", $ptr = 1);
- $task->set("stack", item::root()->id . ":album:1:L");
+ $task->set("stack", item::root()->id . "L1");
$state = self::FIX_STATE_RUN_MPTT;
break;
case self::FIX_STATE_RUN_MPTT:
$ptr = $task->get("ptr");
$stack = explode(" ", $task->get("stack"));
- list ($id, $type, $level, $ptr_mode) = explode(":", array_pop($stack));
- if ($ptr_mode == "L") {
- if ($type == "album") {
- // Albums could be parent nodes.
- $stack[] = "$id:$type:$level:R";
- db::build()
- ->update("items")
- ->set("left_ptr", $ptr++)
- ->where("id", "=", $id)
- ->execute();
+ preg_match("/([0-9]+)([A-Z])([0-9]+)/", array_pop($stack), $matches); // e.g. "12345L10"
+ list ( , $id, $ptr_mode, $level) = $matches; // Skip the 0th entry of matches.
+ switch ($ptr_mode) {
+ case "L":
+ // Albums could be parent nodes.
+ $stack[] = "{$id}R{$level}";
+ db::build()
+ ->update("items")
+ ->set("left_ptr", $ptr++)
+ ->where("id", "=", $id)
+ ->execute();
- $level++;
- foreach (db::build()
- ->select(array("id", "type"))
- ->from("items")
- ->where("parent_id", "=", $id)
- ->order_by("left_ptr", "DESC") // DESC since array_pop effectively reverses them
- ->execute() as $child) {
- $stack[] = "{$child->id}:{$child->type}:$level:L";
- }
- $completed++;
- } else {
- // Non-albums must be leaf nodes.
- db::build()
- ->update("items")
- ->set("left_ptr", $ptr++)
- ->set("right_ptr", $ptr++)
- ->set("level", $level)
- ->set("relative_path_cache", null)
- ->set("relative_url_cache", null)
- ->where("id", "=", $id)
- ->execute();
- $completed += 2; // we updated two pointers
+ $level++;
+ foreach (db::build()
+ ->select(array("id", "type"))
+ ->from("items")
+ ->where("parent_id", "=", $id)
+ ->order_by("left_ptr", "DESC") // DESC since array_pop effectively reverses them
+ ->execute() as $child) {
+ $stack[] = ($child->type == "album") ? "{$child->id}L{$level}" : "{$child->id}B{$level}";
}
- } else if ($ptr_mode == "R") {
+ $completed++;
+ break;
+ case "B":
+ // Non-albums must be leaf nodes.
+ db::build()
+ ->update("items")
+ ->set("left_ptr", $ptr++)
+ ->set("right_ptr", $ptr++)
+ ->set("level", $level)
+ ->set("relative_path_cache", null)
+ ->set("relative_url_cache", null)
+ ->where("id", "=", $id)
+ ->execute();
+ $completed += 2; // we updated two pointers
+ break;
+ case "R":
db::build()
->update("items")
->set("right_ptr", $ptr++)