summaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
authorEvan Prodromou <evan@prodromou.name>2008-07-22 12:02:13 -0400
committerEvan Prodromou <evan@prodromou.name>2008-07-22 12:02:13 -0400
commit64ed01f0aff569da2fd4ed589df9ed4ee9852cb7 (patch)
treed385c10c3aef1408bf62fc9003bb2d697536e299 /actions
parentab1f2ff9d07088c7a3607ee6d05b1042d735960d (diff)
centralize and optimize with-friends query
darcs-hash:20080722160213-84dde-2e466b9cc4601a8cb7237770a7df17a2f9dcadb9.gz
Diffstat (limited to 'actions')
-rw-r--r--actions/all.php28
-rw-r--r--actions/allrss.php12
-rw-r--r--actions/twitapistatuses.php12
3 files changed, 17 insertions, 35 deletions
diff --git a/actions/all.php b/actions/all.php
index 20aea7668..3d3d1c356 100644
--- a/actions/all.php
+++ b/actions/all.php
@@ -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++) {
diff --git a/actions/allrss.php b/actions/allrss.php
index 26e3f5241..a64b47641 100644
--- a/actions/allrss.php
+++ b/actions/allrss.php
@@ -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()) {
diff --git a/actions/twitapistatuses.php b/actions/twitapistatuses.php
index 47e3ffcd9..749f2f084 100644
--- a/actions/twitapistatuses.php
+++ b/actions/twitapistatuses.php
@@ -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();