diff options
author | Bharat Mediratta <bharat@menalto.com> | 2008-12-16 04:29:00 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2008-12-16 04:29:00 +0000 |
commit | d9e02a5d0c1a81925df33a9b25501fc90db91451 (patch) | |
tree | a10bc2a56861cd1c1adb2241d8e877ba12fcd2ae /core/helpers/access.php | |
parent | dc089173456c95dcec1e6184b8e6b5b2810ced52 (diff) |
Various optimizations:
o Add model_cache::get() which caches models avoiding duplicate lookups
o Stop using ORM relationships for Item_Model::owner so that we can use caching
o For Item_Model::xxx_edit fields, don't make them editable for guests
o Other minor stuff.
These optimizations reduce the number of queries for a 9-photos page from ~200
to ~45. Still way too many!
Diffstat (limited to 'core/helpers/access.php')
-rw-r--r-- | core/helpers/access.php | 48 |
1 files changed, 16 insertions, 32 deletions
diff --git a/core/helpers/access.php b/core/helpers/access.php index f40a5c7c..eda91d65 100644 --- a/core/helpers/access.php +++ b/core/helpers/access.php @@ -79,15 +79,8 @@ class access_Core { * @return boolean */ public static function group_can($group, $perm_name, $item) { - if ($perm_name == "view") { - $resource = $item; - } else { - $resource = ORM::factory("access_cache")->where("item_id", $item->id)->find(); - if (!$resource) { - throw new Exception("@todo MISSING_ACCESS for $item->id"); - } - } - + $resource = $perm_name == "view" ? + $item : model_cache::get("access_cache", $item->id, "item_id"); return $resource->__get("{$perm_name}_{$group->id}") === self::ALLOW; } @@ -103,15 +96,8 @@ class access_Core { return false; } - if ($perm_name == "view") { - $resource = $item; - } else { - $resource = ORM::factory("access_cache")->where("item_id", $item->id)->find(); - if (!$resource) { - throw new Exception("@todo MISSING_ACCESS for $item->id"); - } - } - + $resource = $perm_name == "view" ? + $item : model_cache::get("access_cache", $item->id, "item_id"); foreach (user::active()->groups as $group) { if ($resource->__get("{$perm_name}_{$group->id}") === self::ALLOW) { return true; @@ -135,11 +121,7 @@ class access_Core { if ($album->type != "album") { throw new Exception("@todo INVALID_ALBUM_TYPE not an album"); } - $access = ORM::factory("access_intent")->where("item_id", $album->id)->find(); - if (!$access->loaded) { - throw new Exception("@todo MISSING_ACCESS for $album->id"); - } - + $access = model_cache::get("access_intent", $album->id, "item_id"); $access->__set("{$perm_name}_{$group->id}", $value); $access->save(); @@ -268,17 +250,19 @@ class access_Core { $access_intent->save(); // Create a new access cache entry and copy the parents values. - $parent_access_cache = - ORM::factory("access_cache")->where("item_id", $item->parent()->id)->find(); $access_cache = ORM::factory("access_cache"); $access_cache->item_id = $item->id; - foreach (self::_get_all_groups() as $group) { - foreach (ORM::factory("permission")->find_all() as $perm) { - $field = "{$perm->name}_{$group->id}"; - if ($perm->name == "view") { - $item->$field = $item->parent()->$field; - } else { - $access_cache->$field = $parent_access_cache->$field; + if ($item->id != 1) { + $parent_access_cache = + ORM::factory("access_cache")->where("item_id", $item->parent()->id)->find(); + foreach (self::_get_all_groups() as $group) { + foreach (ORM::factory("permission")->find_all() as $perm) { + $field = "{$perm->name}_{$group->id}"; + if ($perm->name == "view") { + $item->$field = $item->parent()->$field; + } else { + $access_cache->$field = $parent_access_cache->$field; + } } } } |