diff options
author | Zach Copley <zach@controlyourself.ca> | 2008-12-12 02:56:17 -0500 |
---|---|---|
committer | Zach Copley <zach@controlyourself.ca> | 2008-12-12 02:56:17 -0500 |
commit | 3e70bfa28713bc4562c2e615fddfd5310d22fc33 (patch) | |
tree | 443eb563612ad6c75ef7916fee6b66f397f7ec8c /actions/favorited.php | |
parent | 2dc27116cea8a28633d9fdd2d21a7be2e3a9c77f (diff) |
Fixed Popular tab (hopefully)
darcs-hash:20081212075617-7b5ce-c56db92d928c58eaa3fed7e4f226e0fca62e2bbf.gz
Diffstat (limited to 'actions/favorited.php')
-rw-r--r-- | actions/favorited.php | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/actions/favorited.php b/actions/favorited.php index 5f6c19c16..dc8070d06 100644 --- a/actions/favorited.php +++ b/actions/favorited.php @@ -56,12 +56,10 @@ class FavoritedAction extends StreamAction { function show_notices($page) { - // XXX: Make dropoff configurable like tags? - - $qry = - 'SELECT notice_id, sum(exp(-(now() - modified)/864000)) as weight ' . - 'FROM fave GROUP BY notice_id ' . - 'ORDER BY weight DESC'; + $qry = 'SELECT notice.*, sum(exp(-(now() - fave.modified) / %s)) as weight ' . + 'FROM notice JOIN fave ON notice.id = fave.notice_id ' . + 'GROUP BY fave.notice_id ' . + 'ORDER BY weight DESC'; $offset = ($page - 1) * NOTICES_PER_PAGE; $limit = NOTICES_PER_PAGE + 1; @@ -72,25 +70,30 @@ class FavoritedAction extends StreamAction { $qry .= ' LIMIT ' . $offset . ', ' . $limit; } - // XXX: Figure out how to cache these queries. + # Figure out how to cache this query - $fave = new Fave; - $fave->query($qry); + $notice = new Notice; + $notice->query(sprintf($qry, common_config('popular', 'dropoff'))); - $notice_list = array(); + common_element_start('ul', array('id' => 'notices')); - while ($fave->fetch()) { - array_push($notice_list, $fave->notice_id); - } + $cnt = 0; - $notice = new Notice(); + while ($notice->fetch() && $cnt <= NOTICES_PER_PAGE) { + $cnt++; - $notice->query(sprintf('SELECT * FROM notice WHERE id in (%s)', - implode(',', $notice_list))); + if ($cnt > NOTICES_PER_PAGE) { + break; + } - $cnt = $this->show_notice_list($notice); + $item = new NoticeListItem($notice); + $item->show(); + } + + common_element_end('ul'); common_pagination($page > 1, $cnt > NOTICES_PER_PAGE, $page, 'favorited'); } + } |