From 8bf6a29d4e05af5d461da3f01999785dc12ee7da Mon Sep 17 00:00:00 2001 From: Friendika Date: Sun, 18 Sep 2011 19:04:11 -0700 Subject: [PATCH] optimise the commented date view --- boot.php | 4 +- database.sql | 1 + include/items.php | 6 ++- mod/item.php | 11 +++-- mod/network.php | 110 ++++++++++++++-------------------------------- update.php | 19 +++++++- 6 files changed, 65 insertions(+), 86 deletions(-) diff --git a/boot.php b/boot.php index 6e78b21f63..226bc3d019 100644 --- a/boot.php +++ b/boot.php @@ -7,9 +7,9 @@ require_once('include/text.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 ( 'DB_UPDATE_VERSION', 1087 ); +define ( 'DB_UPDATE_VERSION', 1088 ); define ( 'EOL', "
\r\n" ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); diff --git a/database.sql b/database.sql index ff339929ea..444b05faa9 100644 --- a/database.sql +++ b/database.sql @@ -174,6 +174,7 @@ CREATE TABLE IF NOT EXISTS `item` ( `thr-parent` char(255) NOT NULL, `created` 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', `changed` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `owner-name` char(255) NOT NULL, diff --git a/include/items.php b/include/items.php index 735adc7170..b433381a74 100644 --- a/include/items.php +++ b/include/items.php @@ -717,6 +717,7 @@ function item_store($arr,$force_parent = false) { $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['edited'] = ((x($arr,'edited') !== false) ? datetime_convert('UTC','UTC',$arr['edited']) : datetime_convert()); + $arr['commented'] = datetime_convert(); $arr['received'] = datetime_convert(); $arr['changed'] = datetime_convert(); $arr['title'] = ((x($arr,'title')) ? notags(trim($arr['title'])) : ''); @@ -865,9 +866,10 @@ function item_store($arr,$force_parent = false) { 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()), intval($parent_id) ); diff --git a/mod/item.php b/mod/item.php index 38f4c20401..cad72122b8 100644 --- a/mod/item.php +++ b/mod/item.php @@ -501,6 +501,7 @@ function item_post(&$a) { $datarray['author-avatar'] = $author['thumb']; $datarray['created'] = datetime_convert(); $datarray['edited'] = datetime_convert(); + $datarray['commented'] = datetime_convert(); $datarray['received'] = datetime_convert(); $datarray['changed'] = datetime_convert(); $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`, - `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` ) - 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']), intval($datarray['uid']), dbesc($datarray['type']), @@ -578,6 +579,7 @@ function item_post(&$a) { dbesc($datarray['author-avatar']), dbesc($datarray['created']), dbesc($datarray['edited']), + dbesc($datarray['commented']), dbesc($datarray['received']), dbesc($datarray['changed']), dbesc($datarray['uri']), @@ -803,9 +805,10 @@ function item_post(&$a) { // 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()), intval($parent) ); diff --git a/mod/network.php b/mod/network.php index 438b3417d7..5faeee453b 100644 --- a/mod/network.php +++ b/mod/network.php @@ -315,44 +315,27 @@ function network_content(&$a, $update = 0) { else { // Normal conversation view - // Show conversation by activity date - if($order === 'post') { - $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid` - FROM `item` LEFT JOIN `contact` ON `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 `item`.`parent` = `item`.`id` - $sql_extra - ORDER BY `item`.`created` DESC LIMIT %d ,%d ", - intval(local_user()), - intval($a->pager['start']), - intval($a->pager['itemspage']) - ); - } - else { - // $order === 'comment' - // First fetch a known number of parent items + if($order === 'post') + $ordering = "`created`"; + else + $ordering = "`commented`"; + + // Fetch a page full of parent items for this page + + $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid` + FROM `item` LEFT JOIN `contact` ON `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 `item`.`parent` = `item`.`id` + $sql_extra + ORDER BY `item`.$ordering DESC LIMIT %d ,%d ", + intval(local_user()), + 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 $parents_arr = array(); @@ -363,48 +346,21 @@ function network_content(&$a, $update = 0) { $parents_arr[] = $rr['item_id']; $parents_str = implode(', ', $parents_arr); - if($order === 'post') { - // parent created order - $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`, (SELECT `p`.`id`,`p`.`created` FROM `item` AS `p` WHERE `p`.`parent`=`p`.`id`) as `parentitem`, `contact` - 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` = `parentitem`.`id` AND `item`.`parent` IN ( %s ) - $sql_extra - ORDER BY `parentitem`.`created` DESC, `item`.`gravity` ASC, `item`.`created` ASC ", - 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) - ); - } - } + $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`, (SELECT `p`.`id`,`p`.`created`,`p`.`commented` FROM `item` AS `p` WHERE `p`.`parent`=`p`.`id`) as `parentitem`, `contact` + 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` = `parentitem`.`id` AND `item`.`parent` IN ( %s ) + $sql_extra + ORDER BY `parentitem`.$ordering DESC, `item`.`gravity` ASC, `item`.`created` ASC ", + intval(local_user()), + dbesc($parents_str) + ); + } } // Set this so that the conversation function can find out contact info for our wall-wall items diff --git a/update.php b/update.php index f94e78d727..82ae058729 100644 --- a/update.php +++ b/update.php @@ -1,6 +1,6 @@