]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/favorited.php
you can _so_ leave a group if you're its admin
[quix0rs-gnu-social.git] / actions / favorited.php
index 0223564f34e754fbdc27eba4bea23d723b3d29ce..5082f4a4eb3e5ae258c67804516924c73907c686 100644 (file)
@@ -104,6 +104,9 @@ class FavoritedAction extends Action
     {
         parent::prepare($args);
         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
+        
+        common_set_returnto($this->selfUrl());
+        
         return true;
     }
 
@@ -166,8 +169,14 @@ class FavoritedAction extends Action
 
     function showContent()
     {
+        if (common_config('db', 'type') == 'pgsql') {
+            $weightexpr='sum(exp(-extract(epoch from (now() - fave.modified)) / %s))';
+        } else {
+            $weightexpr='sum(exp(-(now() - fave.modified) / %s))';
+        }
+
         $qry = 'SELECT notice.*, '.
-          'sum(exp(-(now() - fave.modified) / %s)) as weight ' .
+          $weightexpr . ' as weight ' .
           'FROM notice JOIN fave ON notice.id = fave.notice_id ' .
           'GROUP BY fave.notice_id ' .
           'ORDER BY weight DESC';
@@ -181,10 +190,9 @@ class FavoritedAction extends Action
             $qry .= ' LIMIT ' . $offset . ', ' . $limit;
         }
 
-        // XXX: Figure out how to cache this query
-
-        $notice = new Notice;
-        $notice->query(sprintf($qry, common_config('popular', 'dropoff')));
+        $notice = Memcached_DataObject::cachedQuery('Notice',
+                                                    sprintf($qry, common_config('popular', 'dropoff')),
+                                                    600);
 
         $nl = new NoticeList($notice, $this);