diff options
author | Kriss Andsten <kriss@sverok.se> | 2010-12-17 11:32:58 +0800 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2010-12-17 12:50:51 +0800 |
commit | 16555935ee45a09b8d5b5b351222631ba2ce2132 (patch) | |
tree | 307dc82a661fb2dcb574ea118283ba302cf447fc | |
parent | 7eaf49a6ca97afbe6c82fc830602e7006d53f704 (diff) |
Fetch permissions for non-albumbs by parent rather than by item, allowing the result to be cached.
-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; } |