]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Fixed Popular tab (hopefully)
authorZach Copley <zach@controlyourself.ca>
Fri, 12 Dec 2008 07:56:17 +0000 (02:56 -0500)
committerZach Copley <zach@controlyourself.ca>
Fri, 12 Dec 2008 07:56:17 +0000 (02:56 -0500)
darcs-hash:20081212075617-7b5ce-c56db92d928c58eaa3fed7e4f226e0fca62e2bbf.gz

actions/favorited.php
config.php.sample
lib/common.php

index 5f6c19c167ab9adf558bb9110e4691d260810438..dc8070d060b1571f9143bb1b84ede62f8ef17b18 100644 (file)
@@ -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');
        }
+
 }
index 5f7a44c6344ea96277c03e881cd95a75ab4c3255..db1a216635a71efe8e93d5551fbc52467fb0d34e 100644 (file)
@@ -96,6 +96,10 @@ $config['sphinx']['port'] = 3312;
 #raise this if traffic is slow, lower it if it's fast
 #$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
 #$config['public']['localonly'] = false;
 
index f727a1cc11248b8415c3fa944171ffdeb0bcb450..b8ecbe1518aac956181cca7a9c97f78310cb4fd0 100644 (file)
@@ -116,6 +116,8 @@ $config =
               'port' => 3312),
                'tag' =>
                array('dropoff' => 864000.0),
+               'popular' =>
+               array('dropoff' => 864000.0),
                'daemon' =>
                array('piddir' => '/var/run',
                          'user' => false,