/** * Count the number of faves a notice already has. Used to initalize * a tally for a notice. * * @param integer $noticeID ID of the notice to count faves for * * @return integer $total total number of time the notice has been favored */ static function countExistingFaves($noticeID) { $fave = new Fave(); $fave->notice_id = $noticeID; $total = $fave->count(); return $total; }
function faveCount() { $c = Cache::instance(); if (!empty($c)) { $cnt = $c->get(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('notice_id'); if (!empty($c)) { $c->set(Cache::key('profile:fave_count:' . $this->id), $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); } return $cnt; }
static function countByProfile(Profile $profile) { $c = Cache::instance(); if (!empty($c)) { $cnt = $c->get(Cache::key('fave:count_by_profile:' . $profile->id)); if (is_integer($cnt)) { return $cnt; } } $faves = new Fave(); $faves->user_id = $profile->id; $cnt = (int) $faves->count('notice_id'); if (!empty($c)) { $c->set(Cache::key('fave:count_by_profile:' . $profile->id), $cnt); } return $cnt; }