diff options
-rw-r--r-- | modules/gallery/helpers/access.php | 18 |
1 files changed, 16 insertions, 2 deletions
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; } |