optimise the commented date view
This commit is contained in:
parent
e2e29b2dea
commit
8bf6a29d4e
4
boot.php
4
boot.php
|
@ -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' );
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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)
|
||||||
);
|
);
|
||||||
|
|
11
mod/item.php
11
mod/item.php
|
@ -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)
|
||||||
);
|
);
|
||||||
|
|
|
@ -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')
|
||||||
|
$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`
|
$r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
|
||||||
FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
|
FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
|
||||||
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
|
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
|
||||||
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
|
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
|
||||||
AND `item`.`parent` = `item`.`id`
|
AND `item`.`parent` = `item`.`id`
|
||||||
$sql_extra
|
$sql_extra
|
||||||
ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
|
ORDER BY `item`.$ordering DESC LIMIT %d ,%d ",
|
||||||
intval(local_user()),
|
intval(local_user()),
|
||||||
intval($a->pager['start']),
|
intval($a->pager['start']),
|
||||||
intval($a->pager['itemspage'])
|
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'])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// 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') {
|
|
||||||
// parent created order
|
|
||||||
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
|
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
|
||||||
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
|
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
|
||||||
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
|
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
|
||||||
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
|
`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`
|
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
|
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
|
||||||
AND `contact`.`id` = `item`.`contact-id`
|
AND `contact`.`id` = `item`.`contact-id`
|
||||||
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
|
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
|
||||||
AND `item`.`parent` = `parentitem`.`id` AND `item`.`parent` IN ( %s )
|
AND `item`.`parent` = `parentitem`.`id` AND `item`.`parent` IN ( %s )
|
||||||
$sql_extra
|
$sql_extra
|
||||||
ORDER BY `parentitem`.`created` DESC, `item`.`gravity` ASC, `item`.`created` ASC ",
|
ORDER BY `parentitem`.$ordering DESC, `item`.`gravity` ASC, `item`.`created` ASC ",
|
||||||
intval(local_user()),
|
intval(local_user()),
|
||||||
dbesc($parents_str)
|
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
|
||||||
|
|
19
update.php
19
update.php
|
@ -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'])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue