]> git.mxchange.org Git - friendica.git/commitdiff
optimise the commented date view
authorFriendika <info@friendika.com>
Mon, 19 Sep 2011 02:04:11 +0000 (19:04 -0700)
committerFriendika <info@friendika.com>
Mon, 19 Sep 2011 02:04:11 +0000 (19:04 -0700)
boot.php
database.sql
include/items.php
mod/item.php
mod/network.php
update.php

index 6e78b21f63e5d5dec19e172eb353512aa15729ff..226bc3d0199c6327d2057e77b550be7b227c511e 100644 (file)
--- 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',                    "<br />\r\n"     );
 define ( 'ATOM_TIME',              'Y-m-d\TH:i:s\Z' );
index ff339929ea99b96d8f7cbed521896517d6d35ab5..444b05faa9f6bc2d18e5da8a513d955c9ca4f28e 100644 (file)
@@ -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,
index 735adc7170f542801c3e55295a88ae0eb38f873f..b433381a74c50faa895b87238765463e1b5a6172 100644 (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['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)
        );
index 38f4c204010854c133c60751aefab0db5127dd32..cad72122b8c00c51dea6d843f98b9eea75c50944 100644 (file)
@@ -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)
        );
index 438b3417d7272f0cef55ddca77f86743ad56f573..5faeee453b3947ee1412d4d6ff5da45b69ce60fa 100644 (file)
@@ -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
-
-                       $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'])
-                       );
-               }
+               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'])
+               );
+
                // 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
index f94e78d727f666e75db21ff490252f8ed343a137..82ae0587296f5a43098a274603c966f36e4615ef 100644 (file)
@@ -1,6 +1,6 @@
 <?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` ");
 }
 
+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'])
+                               );
+               }
+       }
+}