summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2009-07-09 17:28:38 -0700
committerEvan Prodromou <evan@controlyourself.ca>2009-07-09 17:28:38 -0700
commit8b65883f9ddf1cb1b7bdec323722da351fa0cb69 (patch)
tree6dcfeb299efe9088a904d4def7c263618380a692 /classes
parentefd94b4e5423c72a65cdd6acd252e5d00ec98967 (diff)
cache frequently-used subscriber, subscription, notice and fave count values
Diffstat (limited to 'classes')
-rw-r--r--classes/Notice.php2
-rw-r--r--classes/Profile.php128
-rw-r--r--classes/User.php2
3 files changed, 132 insertions, 0 deletions
diff --git a/classes/Notice.php b/classes/Notice.php
index e975cab93..75044cf63 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -356,6 +356,8 @@ class Notice extends Memcached_DataObject
$this->blowTagCache($blowLast);
$this->blowGroupCache($blowLast);
$this->blowConversationCache($blowLast);
+ $profile = Profile::staticGet($this->profile_id);
+ $profile->blowNoticeCount();
}
function blowConversationCache($blowLast=false)
diff --git a/classes/Profile.php b/classes/Profile.php
index a0ed6b3ca..224b61bd2 100644
--- a/classes/Profile.php
+++ b/classes/Profile.php
@@ -337,4 +337,132 @@ class Profile extends Memcached_DataObject
return $profile;
}
+
+ function subscriptionCount()
+ {
+ $c = common_memcache();
+
+ if (!empty($c)) {
+ $cnt = $c->get(common_cache_key('profile:subscription_count:'.$this->id));
+ if (is_integer($cnt)) {
+ return (int) $cnt;
+ }
+ }
+
+ $sub = new Subscription();
+ $sub->subscriber = $this->id;
+
+ $cnt = (int) $sub->count('distinct subscribed');
+
+ $cnt = ($cnt > 0) ? $cnt - 1 : $cnt;
+
+ if (!empty($c)) {
+ $c->set(common_cache_key('profile:subscription_count:'.$this->id), $cnt);
+ }
+
+ common_debug("subscriptionCount == $cnt");
+ return $cnt;
+ }
+
+ function subscriberCount()
+ {
+ $c = common_memcache();
+ if (!empty($c)) {
+ $cnt = $c->get(common_cache_key('profile:subscriber_count:'.$this->id));
+ if (is_integer($cnt)) {
+ return (int) $cnt;
+ }
+ }
+
+ $sub = new Subscription();
+ $sub->subscribed = $this->id;
+
+ $cnt = (int) $sub->count('distinct subscriber');
+
+ $cnt = ($cnt > 0) ? $cnt - 1 : $cnt;
+
+ if (!empty($c)) {
+ $c->set(common_cache_key('profile:subscriber_count:'.$this->id), $cnt);
+ }
+
+ common_debug("subscriberCount == $cnt");
+ return $cnt;
+ }
+
+ function faveCount()
+ {
+ $c = common_memcache();
+ if (!empty($c)) {
+ $cnt = $c->get(common_cache_key('profile:fave_count:'.$this->id));
+ if (is_integer($cnt)) {
+ return (int) $cnt;
+ }
+ }
+
+ $faves = new Fave();
+ $faves->user_id = $this->id;
+ $cnt = (int) $faves->count('distinct notice_id');
+
+ if (!empty($c)) {
+ $c->set(common_cache_key('profile:fave_count:'.$this->id), $cnt);
+ }
+
+ common_debug("faveCount == $cnt");
+ return $cnt;
+ }
+
+ function noticeCount()
+ {
+ $c = common_memcache();
+
+ if (!empty($c)) {
+ $cnt = $c->get(common_cache_key('profile:notice_count:'.$this->id));
+ if (is_integer($cnt)) {
+ return (int) $cnt;
+ }
+ }
+
+ $notices = new Notice();
+ $notices->profile_id = $this->id;
+ $cnt = (int) $notices->count('distinct id');
+
+ if (!empty($c)) {
+ $c->set(common_cache_key('profile:notice_count:'.$this->id), $cnt);
+ }
+
+ common_debug("noticeCount == $cnt");
+ return $cnt;
+ }
+
+ function blowSubscriberCount()
+ {
+ $c = common_memcache();
+ if (!empty($c)) {
+ $c->delete(common_cache_key('profile:subscriber_count:'.$this->id));
+ }
+ }
+
+ function blowSubscriptionCount()
+ {
+ $c = common_memcache();
+ if (!empty($c)) {
+ $c->delete(common_cache_key('profile:subscription_count:'.$this->id));
+ }
+ }
+
+ function blowFaveCount()
+ {
+ $c = common_memcache();
+ if (!empty($c)) {
+ $c->delete(common_cache_key('profile:fave_count:'.$this->id));
+ }
+ }
+
+ function blowNoticeCount()
+ {
+ $c = common_memcache();
+ if (!empty($c)) {
+ $c->delete(common_cache_key('profile:notice_count:'.$this->id));
+ }
+ }
}
diff --git a/classes/User.php b/classes/User.php
index 04b38a0d2..6c1f149e4 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -494,6 +494,8 @@ class User extends Memcached_DataObject
$cache->delete(common_cache_key('fave:ids_by_user_own:'.$this->id));
$cache->delete(common_cache_key('fave:ids_by_user_own:'.$this->id.';last'));
}
+ $profile = $this->getProfile();
+ $profile->blowFaveCount();
}
function getSelfTags()