centralize and optimize with-friends query

darcs-hash:20080722160213-84dde-2e466b9cc4601a8cb7237770a7df17a2f9dcadb9.gz
This commit is contained in:
Evan Prodromou 2008-07-22 12:02:13 -04:00
parent ab1f2ff9d0
commit 64ed01f0af
7 changed files with 41 additions and 37 deletions

View 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,22 +71,18 @@ class AllAction extends StreamAction {
$this->views_menu();
}
function show_notices($profile) {
function show_notices($user) {
$notice = DB_DataObject::factory('notice');
$page = $this->trimmed('page');
if (!$page) {
$page = 1;
}
# 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;
$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'));

View 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 = $user->noticesWithFriends();
$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');
if ($limit != 0) {
$notice->limit(0, $limit);
}
$notice->find();
while ($notice->fetch()) {

View File

@ -223,17 +223,7 @@ 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->orderBy('created DESC, notice.id DESC');
$notice->$user->noticesWithFriends();
$notice->limit((($page-1)*20), $count);

View 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;
}
}

View File

@ -34,3 +34,6 @@ user_id = user:id
[queue_item]
notice_id = notice:id
[subscription]
subscriber = profile:id
subscribed = profile:id

View 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

View File

@ -19,8 +19,6 @@
if (!defined('LACONICA')) { exit(1); }
define('NOTICES_PER_PAGE', 20);
class StreamAction extends Action {
function handle($args) {