summaryrefslogtreecommitdiff
path: root/modules/user/models/group.php
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2010-12-15 16:28:18 -0800
committerBharat Mediratta <bharat@menalto.com>2010-12-15 16:28:18 -0800
commit1057436b7c483c60b3c128fab993a3b78fac7093 (patch)
tree4b751c613375d9f6970b34f8ec8d0e701aeb8703 /modules/user/models/group.php
parentb9e11a6f93077a2b012e0a4314667c5b0cf06291 (diff)
Cache the result of User_Model::groups() and Group_Model::users() and
invalidate it on save/delete for efficiency. Fixes #1529.
Diffstat (limited to 'modules/user/models/group.php')
-rw-r--r--modules/user/models/group.php8
1 files changed, 7 insertions, 1 deletions
diff --git a/modules/user/models/group.php b/modules/user/models/group.php
index 17d9320b..66c9aafc 100644
--- a/modules/user/models/group.php
+++ b/modules/user/models/group.php
@@ -19,6 +19,7 @@
*/
class Group_Model_Core extends ORM implements Group_Definition {
protected $has_and_belongs_to_many = array("users");
+ protected $users_cache = null;
/**
* @see ORM::delete()
@@ -28,10 +29,14 @@ class Group_Model_Core extends ORM implements Group_Definition {
module::event("group_before_delete", $this);
parent::delete($id);
module::event("group_deleted", $old);
+ unset($this->users_cache);
}
public function users() {
- return $this->users->find_all();
+ if (!$this->users_cache) {
+ $this->users_cache = $this->users->find_all();
+ }
+ return $this->users_cache;
}
/**
@@ -60,6 +65,7 @@ class Group_Model_Core extends ORM implements Group_Definition {
module::event("group_updated", $original, $this);
}
+ unset($this->users_cache);
return $this;
}