From f9e77c4c14c3a213ed8407495d4f71949a3a2339 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 21 Jul 2012 10:38:23 -0700 Subject: Fix the access_cache rebuilding code to not load all missing access caches into the stack, if you're missing enough it'll blow the stack (like, if you truncate the access_caches table). Fixes #1895. --- modules/gallery/helpers/gallery_task.php | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index 9a35ce67..51aec014 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -562,7 +562,7 @@ class gallery_task_Core { case self::FIX_STATE_START_MISSING_ACCESS_CACHES: $stack = array(); - foreach (self::find_missing_access_caches() as $row) { + foreach (self::find_missing_access_caches_limited(500) as $row) { $stack[] = $row->id; } if ($stack) { @@ -582,11 +582,20 @@ class gallery_task_Core { $task->set("stack", implode(" ", $stack)); $completed++; if (empty($stack)) { - // The new cache rows are there, but they're incorrectly populated so we have to fix - // them. If this turns out to be too slow, we'll have to refactor - // access::recalculate_permissions to allow us to do it in slices. - access::recalculate_album_permissions(item::root()); - $state = self::FIX_STATE_DONE; + // Refill the stack + foreach (self::find_missing_access_caches_limited(500) as $row) { + $stack[] = $row->id; + } + + if (empty($stack)) { + // The new cache rows are there, but they're incorrectly populated so we have to fix + // them. If this turns out to be too slow, we'll have to refactor + // access::recalculate_permissions to allow us to do it in slices. + access::recalculate_album_permissions(item::root()); + $state = self::FIX_STATE_DONE; + } else { + $task->set("stack", implode(" ", $stack)); + } } break; } @@ -633,11 +642,16 @@ class gallery_task_Core { } static function find_missing_access_caches() { + return self::find_missing_access_caches_limited(1 << 16); + } + + static function find_missing_access_caches_limited($limit) { return db::build() ->select("items.id") ->from("items") ->join("access_caches", "items.id", "access_caches.item_id", "left") ->where("access_caches.id", "is", null) + ->limit($limit) ->execute(); } } \ No newline at end of file -- cgit v1.2.3