summaryrefslogtreecommitdiff
path: root/modules/gallery
diff options
context:
space:
mode:
authorshadlaws <shad@shadlaws.com>2013-05-14 13:35:09 +0200
committershadlaws <shad@shadlaws.com>2013-05-14 13:35:09 +0200
commit2ebe38b148da8830f2b4064bb738633c511c97cc (patch)
tree085476c00b55ecdde2f41b4fd259b2855ea2987b /modules/gallery
parent4d8fbd1b9d61463ed255b3a73e6e6b3574d97923 (diff)
#2069 - Change "Fix your Gallery" task go faster and be more comprehensive.
- optimize MPTT pointer rebuilding for leaf nodes (i.e. non-albums). - reverse order_by to try and preserve existing tree ordering. - reset item level while we're here. - use "$stack[] = 123" instead of array_push($stack, 123) since it's faster. --HG-- extra : source : 297e4c0eccc5a7940224ff8e908b366e83017354
Diffstat (limited to 'modules/gallery')
-rw-r--r--modules/gallery/helpers/gallery_task.php50
1 files changed, 34 insertions, 16 deletions
diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php
index a79cb2d5..ac98831b 100644
--- a/modules/gallery/helpers/gallery_task.php
+++ b/modules/gallery/helpers/gallery_task.php
@@ -398,42 +398,60 @@ class gallery_task_Core {
switch ($state) {
case self::FIX_STATE_START_MPTT:
$task->set("ptr", $ptr = 1);
- $task->set("stack", item::root()->id . ":L");
+ $task->set("stack", item::root()->id . ":album:1:L");
$state = self::FIX_STATE_RUN_MPTT;
break;
case self::FIX_STATE_RUN_MPTT:
$ptr = $task->get("ptr");
$stack = explode(" ", $task->get("stack"));
- list ($id, $ptr_mode) = explode(":", array_pop($stack));
+ list ($id, $type, $level, $ptr_mode) = explode(":", array_pop($stack));
if ($ptr_mode == "L") {
- $stack[] = "$id:R";
- db::build()
- ->update("items")
- ->set("left_ptr", $ptr++)
- ->where("id", "=", $id)
- ->execute();
+ 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();
- foreach (db::build()
- ->select(array("id"))
- ->from("items")
- ->where("parent_id", "=", $id)
- ->order_by("left_ptr", "ASC")
- ->execute() as $child) {
- array_push($stack, "{$child->id}:L");
+ $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
}
} else if ($ptr_mode == "R") {
db::build()
->update("items")
->set("right_ptr", $ptr++)
+ ->set("level", $level)
->set("relative_path_cache", null)
->set("relative_url_cache", null)
->where("id", "=", $id)
->execute();
+ $completed++;
}
$task->set("ptr", $ptr);
$task->set("stack", implode(" ", $stack));
- $completed++;
if (empty($stack)) {
$state = self::FIX_STATE_START_DUPE_SLUGS;