From 4476a4286f012bc72b274133203c6a9c1a6c00b3 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 16 Sep 2008 13:44:00 -0400 Subject: rationalize with repository version darcs-hash:20080916174400-84dde-63781c5cd6a7c9a3dbc765dfa15084e3372effd5.gz --- classes/User.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'classes') diff --git a/classes/User.php b/classes/User.php index 62f077739..84a980db4 100644 --- a/classes/User.php +++ b/classes/User.php @@ -153,6 +153,52 @@ class User extends DB_DataObject return $notice; } + + function favoriteNotices($offset=0, $limit=20) { + + $notice = new Notice(); + + $notice->query('SELECT notice.* ' . + 'FROM notice JOIN fave on notice.id = fave.notice_id ' . + 'WHERE fave.user_id = ' . $this->id . ' ' . + 'ORDER BY notice.created DESC, notice.id DESC ' . + 'LIMIT ' . $offset . ', ' . $limit); + + return $notice; + } + + function noticesWithFriendsWindow() { + + $cache = new Memcache(); + $res = $cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port')); + + if (!$res) { + return NULL; + } + + $notices = $cache->get(common_cache_key('user:notices_with_friends:' . $this->id)); + + if ($notices) { + return $notices; + } + + $notice = new Notice(); + + $notice->query('SELECT notice.* ' . + 'FROM notice JOIN subscription on notice.profile_id = subscription.subscribed ' . + 'WHERE subscription.subscriber = ' . $this->id . ' ' . + 'ORDER BY created DESC, notice.id DESC ' . + 'LIMIT 0, ' . WITHFRIENDS_CACHE_WINDOW); + + $notices = array(); + + while ($notice->fetch()) { + $notices[] = clone($notice); + } + + $cache->set(common_cache_key('user:notices_with_friends:' . $this->id), $notices); + return $notices; + } static function register($fields) { -- cgit v1.2.3-54-g00ecf