X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=classes%2FProfile.php;h=224b61bd2ee3508f19789923879b07f5ae3582e5;hb=8b65883f9ddf1cb1b7bdec323722da351fa0cb69;hp=a0ed6b3ca349e0da83dc161a409893f821cdb8af;hpb=efd94b4e5423c72a65cdd6acd252e5d00ec98967;p=quix0rs-gnu-social.git diff --git a/classes/Profile.php b/classes/Profile.php index a0ed6b3ca3..224b61bd2e 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)); + } + } }