optimise the commented date view

This commit is contained in:
Friendika 2011-09-18 19:04:11 -07:00
parent e2e29b2dea
commit 8bf6a29d4e
6 changed files with 65 additions and 86 deletions

View file

@ -7,9 +7,9 @@ require_once('include/text.php');
require_once("include/pgettext.php"); require_once("include/pgettext.php");
define ( 'FRIENDIKA_VERSION', '2.2.1107' ); define ( 'FRIENDIKA_VERSION', '2.3.1108' );
define ( 'DFRN_PROTOCOL_VERSION', '2.21' ); define ( 'DFRN_PROTOCOL_VERSION', '2.21' );
define ( 'DB_UPDATE_VERSION', 1087 ); define ( 'DB_UPDATE_VERSION', 1088 );
define ( 'EOL', "<br />\r\n" ); define ( 'EOL', "<br />\r\n" );
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );

View file

@ -174,6 +174,7 @@ CREATE TABLE IF NOT EXISTS `item` (
`thr-parent` char(255) NOT NULL, `thr-parent` char(255) NOT NULL,
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`edited` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `edited` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`commented` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`received` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `received` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`changed` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `changed` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`owner-name` char(255) NOT NULL, `owner-name` char(255) NOT NULL,

View file

@ -717,6 +717,7 @@ function item_store($arr,$force_parent = false) {
$arr['owner-avatar'] = ((x($arr,'owner-avatar')) ? notags(trim($arr['owner-avatar'])) : ''); $arr['owner-avatar'] = ((x($arr,'owner-avatar')) ? notags(trim($arr['owner-avatar'])) : '');
$arr['created'] = ((x($arr,'created') !== false) ? datetime_convert('UTC','UTC',$arr['created']) : datetime_convert()); $arr['created'] = ((x($arr,'created') !== false) ? datetime_convert('UTC','UTC',$arr['created']) : datetime_convert());
$arr['edited'] = ((x($arr,'edited') !== false) ? datetime_convert('UTC','UTC',$arr['edited']) : datetime_convert()); $arr['edited'] = ((x($arr,'edited') !== false) ? datetime_convert('UTC','UTC',$arr['edited']) : datetime_convert());
$arr['commented'] = datetime_convert();
$arr['received'] = datetime_convert(); $arr['received'] = datetime_convert();
$arr['changed'] = datetime_convert(); $arr['changed'] = datetime_convert();
$arr['title'] = ((x($arr,'title')) ? notags(trim($arr['title'])) : ''); $arr['title'] = ((x($arr,'title')) ? notags(trim($arr['title'])) : '');
@ -865,9 +866,10 @@ function item_store($arr,$force_parent = false) {
intval($current_post) intval($current_post)
); );
// update the timestamp on the parent // update the commented timestamp on the parent
q("UPDATE `item` set `changed` = '%s' WHERE `id` = %d LIMIT 1", q("UPDATE `item` set `commented` = '%s', `changed` = '%s' WHERE `id` = %d LIMIT 1",
dbesc(datetime_convert()),
dbesc(datetime_convert()), dbesc(datetime_convert()),
intval($parent_id) intval($parent_id)
); );

View file

@ -501,6 +501,7 @@ function item_post(&$a) {
$datarray['author-avatar'] = $author['thumb']; $datarray['author-avatar'] = $author['thumb'];
$datarray['created'] = datetime_convert(); $datarray['created'] = datetime_convert();
$datarray['edited'] = datetime_convert(); $datarray['edited'] = datetime_convert();
$datarray['commented'] = datetime_convert();
$datarray['received'] = datetime_convert(); $datarray['received'] = datetime_convert();
$datarray['changed'] = datetime_convert(); $datarray['changed'] = datetime_convert();
$datarray['uri'] = $uri; $datarray['uri'] = $uri;
@ -561,9 +562,9 @@ function item_post(&$a) {
$r = q("INSERT INTO `item` (`guid`, `uid`,`type`,`wall`,`gravity`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`, $r = q("INSERT INTO `item` (`guid`, `uid`,`type`,`wall`,`gravity`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`,
`author-name`, `author-link`, `author-avatar`, `created`, `edited`, `received`, `changed`, `uri`, `thr-parent`, `title`, `body`, `app`, `location`, `coord`, `author-name`, `author-link`, `author-avatar`, `created`, `edited`, `commented`, `received`, `changed`, `uri`, `thr-parent`, `title`, `body`, `app`, `location`, `coord`,
`tag`, `inform`, `verb`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private`, `pubmail`, `attach`, `bookmark` ) `tag`, `inform`, `verb`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private`, `pubmail`, `attach`, `bookmark` )
VALUES( '%s', %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d )", VALUES( '%s', %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d )",
dbesc($datarray['guid']), dbesc($datarray['guid']),
intval($datarray['uid']), intval($datarray['uid']),
dbesc($datarray['type']), dbesc($datarray['type']),
@ -578,6 +579,7 @@ function item_post(&$a) {
dbesc($datarray['author-avatar']), dbesc($datarray['author-avatar']),
dbesc($datarray['created']), dbesc($datarray['created']),
dbesc($datarray['edited']), dbesc($datarray['edited']),
dbesc($datarray['commented']),
dbesc($datarray['received']), dbesc($datarray['received']),
dbesc($datarray['changed']), dbesc($datarray['changed']),
dbesc($datarray['uri']), dbesc($datarray['uri']),
@ -803,9 +805,10 @@ function item_post(&$a) {
// NOTREACHED // NOTREACHED
} }
// update the timestamp on the parent // update the commented timestamp on the parent
q("UPDATE `item` set `changed` = '%s' WHERE `id` = %d LIMIT 1", q("UPDATE `item` set `commented` = '%s', `changed` = '%s' WHERE `id` = %d LIMIT 1",
dbesc(datetime_convert()),
dbesc(datetime_convert()), dbesc(datetime_convert()),
intval($parent) intval($parent)
); );

View file

@ -315,44 +315,27 @@ function network_content(&$a, $update = 0) {
else { else {
// Normal conversation view // Normal conversation view
// Show conversation by activity date
if($order === 'post') { if($order === 'post')
$r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid` $ordering = "`created`";
FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` else
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 $ordering = "`commented`";
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
AND `item`.`parent` = `item`.`id` // Fetch a page full of parent items for this page
$sql_extra
ORDER BY `item`.`created` DESC LIMIT %d ,%d ", $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
intval(local_user()), FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
intval($a->pager['start']), WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
intval($a->pager['itemspage']) AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
); AND `item`.`parent` = `item`.`id`
} $sql_extra
else { ORDER BY `item`.$ordering DESC LIMIT %d ,%d ",
// $order === 'comment' intval(local_user()),
// First fetch a known number of parent items intval($a->pager['start']),
intval($a->pager['itemspage'])
);
$r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
, (SELECT `_com`.`parent`,max(`_com`.`created`) as `created`
FROM `item` AS `_com`
WHERE `_com`.`uid`=%d AND
(`_com`.`parent`!=`_com`.`id` OR `_com`.`id` NOT IN (SELECT `__com`.`parent` FROM `item` as `__com` WHERE `__com`.`parent`!=`__com`.`id`))
GROUP BY `_com`.`parent` ORDER BY `created` DESC) AS `com`
WHERE `item`.`id`=`com`.`parent` AND
`item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
$sql_extra
ORDER BY `com`.`created` DESC LIMIT %d ,%d ",
intval(local_user()),
intval(local_user()),
intval($a->pager['start']),
intval($a->pager['itemspage'])
);
}
// Then fetch all the children of the parents that are on this page // Then fetch all the children of the parents that are on this page
$parents_arr = array(); $parents_arr = array();
@ -363,48 +346,21 @@ function network_content(&$a, $update = 0) {
$parents_arr[] = $rr['item_id']; $parents_arr[] = $rr['item_id'];
$parents_str = implode(', ', $parents_arr); $parents_str = implode(', ', $parents_arr);
if($order === 'post') { $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
// parent created order `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`, `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, FROM `item`, (SELECT `p`.`id`,`p`.`created`,`p`.`commented` FROM `item` AS `p` WHERE `p`.`parent`=`p`.`id`) as `parentitem`, `contact`
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
FROM `item`, (SELECT `p`.`id`,`p`.`created` FROM `item` AS `p` WHERE `p`.`parent`=`p`.`id`) as `parentitem`, `contact` AND `contact`.`id` = `item`.`contact-id`
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
AND `contact`.`id` = `item`.`contact-id` AND `item`.`parent` = `parentitem`.`id` AND `item`.`parent` IN ( %s )
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 $sql_extra
AND `item`.`parent` = `parentitem`.`id` AND `item`.`parent` IN ( %s ) ORDER BY `parentitem`.$ordering DESC, `item`.`gravity` ASC, `item`.`created` ASC ",
$sql_extra intval(local_user()),
ORDER BY `parentitem`.`created` DESC, `item`.`gravity` ASC, `item`.`created` ASC ", dbesc($parents_str)
intval(local_user()), );
dbesc($parents_str) }
);
}
else {
// $order === 'comment'
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
FROM `item`, `contact`,
(SELECT `_com`.`parent`,max(`_com`.`created`) as `created`
FROM `item` AS `_com`
WHERE `_com`.`uid`=%d AND
(`_com`.`parent`!=`_com`.`id` OR `_com`.`id` NOT IN (SELECT `__com`.`parent` FROM `item` as `__com` WHERE `__com`.`parent`!=`__com`.`id`))
GROUP BY `_com`.`parent` ORDER BY `created` DESC) AS `com`
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
AND `contact`.`id` = `item`.`contact-id`
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
AND `item`.`parent` = `com`.`parent` AND `item`.`parent` IN ( %s )
$sql_extra
ORDER BY `com`.`created` DESC, `item`.`gravity` ASC, `item`.`created` ASC ",
intval(local_user()),
intval(local_user()),
dbesc($parents_str)
);
}
}
} }
// Set this so that the conversation function can find out contact info for our wall-wall items // Set this so that the conversation function can find out contact info for our wall-wall items

View file

@ -1,6 +1,6 @@
<?php <?php
define( 'UPDATE_VERSION' , 1087 ); define( 'UPDATE_VERSION' , 1088 );
/** /**
* *
@ -726,3 +726,20 @@ function update_1086() {
q("ALTER TABLE `item` ADD `bookmark` tinyint(1) NOT NULL DEFAULT '0' AFTER `starred` "); q("ALTER TABLE `item` ADD `bookmark` tinyint(1) NOT NULL DEFAULT '0' AFTER `starred` ");
} }
function update_1087() {
q("ALTER TABLE `item` ADD `commented` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `edited` ");
$r = q("SELECT `id` FROM `item` WHERE `parent` = `id` ");
if(count($r)) {
foreach($r as $rr) {
$x = q("SELECT max(`created`) AS `cdate` FROM `item` WHERE `parent` = %d LIMIT 1",
intval($rr['id'])
);
if(count($x))
q("UPDATE `item` SET `commented` = '%s' WHERE `id` = %d LIMIT 1",
dbesc($x[0]['cdate']),
intval($rr['id'])
);
}
}
}