From 16555935ee45a09b8d5b5b351222631ba2ce2132 Mon Sep 17 00:00:00 2001 From: Kriss Andsten Date: Fri, 17 Dec 2010 11:32:58 +0800 Subject: Fetch permissions for non-albumbs by parent rather than by item, allowing the result to be cached. --- modules/gallery/helpers/access.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/gallery/helpers/access.php b/modules/gallery/helpers/access.php index a7ac3f9f..bfe02b3c 100644 --- a/modules/gallery/helpers/access.php +++ b/modules/gallery/helpers/access.php @@ -99,8 +99,15 @@ class access_Core { return true; } + /* + We do this for cache reasons - if you check n photos in an album, it makes more sense + to check the album permissions once and let the cache deal with that, rather than check + every item individually and generate cache misses. + */ + $id = ($item->type == 'album') ? $item->id : $item->parent_id; $resource = $perm_name == "view" ? - $item : model_cache::get("access_cache", $item->id, "item_id"); + $item : model_cache::get("access_cache", $id, "item_id"); + foreach ($user->groups() as $group) { if ($resource->__get("{$perm_name}_{$group->id}") === access::ALLOW) { return true; @@ -136,8 +143,15 @@ class access_Core { * @return boolean */ static function group_can($group, $perm_name, $item) { + /* + We do this for cache reasons - if you check n photos in an album, it makes more sense + to check the album permissions once and let the cache deal with that, rather than check + every item individually and generate cache misses. + */ + $id = ($item->type == 'album') ? $item->id : $item->parent_id; $resource = $perm_name == "view" ? - $item : model_cache::get("access_cache", $item->id, "item_id"); + $item : model_cache::get("access_cache", $id, "item_id"); + return $resource->__get("{$perm_name}_{$group->id}") === access::ALLOW; } -- cgit v1.2.3