summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2012-07-21 10:38:23 -0700
committerBharat Mediratta <bharat@menalto.com>2012-07-21 10:38:23 -0700
commitf9e77c4c14c3a213ed8407495d4f71949a3a2339 (patch)
treee29f2c34dee9f4ee68bee38578a89fdce814c511 /modules
parente4daa4283035197136850ae2c409dffc79fa8459 (diff)
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.
Diffstat (limited to 'modules')
-rw-r--r--modules/gallery/helpers/gallery_task.php26
1 files changed, 20 insertions, 6 deletions
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