Fixed Popular tab (hopefully)

darcs-hash:20081212075617-7b5ce-c56db92d928c58eaa3fed7e4f226e0fca62e2bbf.gz
This commit is contained in:
Zach Copley 2008-12-12 02:56:17 -05:00
parent 2dc27116ce
commit 3e70bfa287
3 changed files with 27 additions and 18 deletions

View File

@ -56,11 +56,9 @@ class FavoritedAction extends StreamAction {
function show_notices($page) { function show_notices($page) {
// XXX: Make dropoff configurable like tags? $qry = 'SELECT notice.*, sum(exp(-(now() - fave.modified) / %s)) as weight ' .
'FROM notice JOIN fave ON notice.id = fave.notice_id ' .
$qry = 'GROUP BY fave.notice_id ' .
'SELECT notice_id, sum(exp(-(now() - modified)/864000)) as weight ' .
'FROM fave GROUP BY notice_id ' .
'ORDER BY weight DESC'; 'ORDER BY weight DESC';
$offset = ($page - 1) * NOTICES_PER_PAGE; $offset = ($page - 1) * NOTICES_PER_PAGE;
@ -72,25 +70,30 @@ class FavoritedAction extends StreamAction {
$qry .= ' LIMIT ' . $offset . ', ' . $limit; $qry .= ' LIMIT ' . $offset . ', ' . $limit;
} }
// XXX: Figure out how to cache these queries. # Figure out how to cache this query
$fave = new Fave; $notice = new Notice;
$fave->query($qry); $notice->query(sprintf($qry, common_config('popular', 'dropoff')));
$notice_list = array(); common_element_start('ul', array('id' => 'notices'));
while ($fave->fetch()) { $cnt = 0;
array_push($notice_list, $fave->notice_id);
while ($notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
$cnt++;
if ($cnt > NOTICES_PER_PAGE) {
break;
} }
$notice = new Notice(); $item = new NoticeListItem($notice);
$item->show();
}
$notice->query(sprintf('SELECT * FROM notice WHERE id in (%s)', common_element_end('ul');
implode(',', $notice_list)));
$cnt = $this->show_notice_list($notice);
common_pagination($page > 1, $cnt > NOTICES_PER_PAGE, common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
$page, 'favorited'); $page, 'favorited');
} }
} }

View File

@ -96,6 +96,10 @@ $config['sphinx']['port'] = 3312;
#raise this if traffic is slow, lower it if it's fast #raise this if traffic is slow, lower it if it's fast
#$config['tag']['dropoff'] = 86400.0 * 10; #$config['tag']['dropoff'] = 86400.0 * 10;
#exponential decay factor for popular (most favorited notices)
#default 10 days -- similar to tag dropoff
#$config['popular']['dropoff'] = 86400.0 * 10;
#optionally show non-local messages in public timeline #optionally show non-local messages in public timeline
#$config['public']['localonly'] = false; #$config['public']['localonly'] = false;

View File

@ -116,6 +116,8 @@ $config =
'port' => 3312), 'port' => 3312),
'tag' => 'tag' =>
array('dropoff' => 864000.0), array('dropoff' => 864000.0),
'popular' =>
array('dropoff' => 864000.0),
'daemon' => 'daemon' =>
array('piddir' => '/var/run', array('piddir' => '/var/run',
'user' => false, 'user' => false,