]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
centralize and optimize with-friends query
authorEvan Prodromou <evan@prodromou.name>
Tue, 22 Jul 2008 16:02:13 +0000 (12:02 -0400)
committerEvan Prodromou <evan@prodromou.name>
Tue, 22 Jul 2008 16:02:13 +0000 (12:02 -0400)
darcs-hash:20080722160213-84dde-2e466b9cc4601a8cb7237770a7df17a2f9dcadb9.gz

actions/all.php
actions/allrss.php
actions/twitapistatuses.php
classes/User.php
classes/stoica.links.ini
lib/common.php
lib/stream.php

index 20aea766868552348f4b275a84bd29642a85dccb..3d3d1c3563188b8c23e7cfc1e82f14f6b603b132 100644 (file)
@@ -48,7 +48,7 @@ class AllAction extends StreamAction {
                                                   array($this, 'show_header'), $user,
                                                   array($this, 'show_top'));
 
-               $this->show_notices($profile);
+               $this->show_notices($user);
 
                common_show_footer();
        }
@@ -71,23 +71,19 @@ class AllAction extends StreamAction {
                $this->views_menu();
        }
 
-       function show_notices($profile) {
-
-               $notice = DB_DataObject::factory('notice');
-
-               # XXX: chokety and bad
-
-               $notice->whereAdd('EXISTS (SELECT subscribed from subscription where subscriber = '.$profile->id.' and subscribed = notice.profile_id)', 'OR');
-               $notice->whereAdd('profile_id = ' . $profile->id, 'OR');
-
-               $notice->orderBy('created DESC, notice.id DESC');
-
-               $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
+       function show_notices($user) {
 
+               $page = $this->trimmed('page');
+               if (!$page) {
+                       $page = 1;
+               }
+               
+               $notice = $user->noticesWithFriends($page);
+               # XXX: revisit constant scope
+               
                $notice->limit((($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1);
-
-               $cnt = $notice->find();
-
+               
+               
                if ($cnt > 0) {
                        common_element_start('ul', array('id' => 'notices'));
                        for ($i = 0; $i < min($cnt, NOTICES_PER_PAGE); $i++) {
index 26e3f5241eb4888742e27faac378d8d2feeb4d04..a64b47641462494c15624ffe36a820f2d93b5759 100644 (file)
@@ -42,17 +42,13 @@ class AllrssAction extends Rss10Action {
        function get_notices($limit=0) {
 
                $user = $this->user;
-               $notices = array();
-
-               $notice = DB_DataObject::factory('notice');
-
-               $notice->whereAdd('EXISTS (SELECT subscribed from subscription where subscriber = '.$user->id.' and subscribed = notice.profile_id)', 'OR');
-               $notice->whereAdd('profile_id = ' . $user->id, 'OR');
-
-               $notice->orderBy('created DESC, notice.id DESC');
+               
+               $notice = $user->noticesWithFriends();
+               
                if ($limit != 0) {
                        $notice->limit(0, $limit);
                }
+               
                $notice->find();
 
                while ($notice->fetch()) {
index 47e3ffcd9761da5261c126f50ed20414e4353bf4..749f2f0849fb7f8d852bf0d60555524ff682ee65 100644 (file)
@@ -223,18 +223,8 @@ class TwitapistatusesAction extends TwitterapiAction {
                $link = common_local_url('all', array('nickname' => $user->nickname));
                $subtitle = sprintf(_("Updates from %s and friends on %s!"), $user->nickname, $sitename);
 
-               $notice = new Notice();
-
-               # XXX: chokety and bad
-
-               $notice->whereAdd('EXISTS (SELECT subscribed from subscription where subscriber = '.$profile->id.' and subscribed = notice.profile_id)', 'OR');
-               $notice->whereAdd('profile_id = ' . $profile->id, 'OR');
-
-               # XXX: since
-               # XXX: since_id
+               $notice->$user->noticesWithFriends();
                
-               $notice->orderBy('created DESC, notice.id DESC');
-
                $notice->limit((($page-1)*20), $count);
 
                $cnt = $notice->find();
index e4928eb34af7200f39a5fbd15a5ca16a1367abaf..1772b82e0ebf8427f07dda3ec57cfe8e77a7499a 100644 (file)
@@ -128,4 +128,23 @@ class User extends DB_DataObject
                
                return true;
        }
+       
+       function noticesWithFriends() {
+               
+               $notice = new Notice();
+               
+               $notice->selectAs();
+               
+               $subscription = new Subscription();
+               
+               $subscription->subscriber = $this->id;
+               
+               $notice->joinAdd($subscription);
+               $notice->whereAdd('notice.profile_id = subscription.subscribed');
+               $notice->selectAs($subscription, 'sub_%');
+               
+               $notice->orderBy('created DESC, notice.id DESC');
+
+               return $notice;
+       }
 }
index 7e4e3613cd217bdbec376a5f3dc6423f1f7fba25..bb849cbf2f0924215945f106f49fdbb81a600175 100644 (file)
@@ -34,3 +34,6 @@ user_id = user:id
 [queue_item]
 notice_id = notice:id
 
+[subscription]
+subscriber = profile:id
+subscribed = profile:id
index e7d69303c83f8ff749c4dd5c6079ea7a485627d9..ca668d8c28d751fe80336b90c817c8b6484002be 100644 (file)
@@ -26,6 +26,8 @@ define('AVATAR_STREAM_SIZE', 48);
 define('AVATAR_MINI_SIZE', 24);
 define('MAX_AVATAR_SIZE', 256 * 1024);
 
+define('NOTICES_PER_PAGE', 20);
+
 define_syslog_variables();
 
 # global configuration object
index ad65e2d2a293702231a513b0959225d68f1dd4da..a595958e44e27a8e806a49f205064b8917bdfd8f 100644 (file)
@@ -19,8 +19,6 @@
 
 if (!defined('LACONICA')) { exit(1); }
 
-define('NOTICES_PER_PAGE', 20);
-
 class StreamAction extends Action {
 
        function handle($args) {