Even more SQL improvements.

This commit is contained in:
Michael Vogel 2014-03-16 17:12:56 +01:00
parent 6e7bd68ebb
commit bbf9378a49
10 changed files with 109 additions and 88 deletions

View file

@ -1202,7 +1202,7 @@ CREATE TABLE IF NOT EXISTS `unique_contacts` (
CREATE TABLE IF NOT EXISTS `thread` ( CREATE TABLE IF NOT EXISTS `thread` (
`iid` int(10) unsigned NOT NULL DEFAULT '0', `iid` int(10) unsigned NOT NULL DEFAULT '0',
`uid` int(10) unsigned NOT NULL DEFAULT '0', `uid` int(10) unsigned NOT NULL DEFAULT '0',
`contact-id` int(10) unsigned NOT NULL DEFAULT '0', `contact-id` int(11) unsigned NOT NULL DEFAULT '0',
`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', `commented` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
@ -1223,15 +1223,13 @@ CREATE TABLE IF NOT EXISTS `thread` (
`mention` tinyint(1) NOT NULL DEFAULT '0', `mention` tinyint(1) NOT NULL DEFAULT '0',
`network` char(32) NOT NULL, `network` char(32) NOT NULL,
PRIMARY KEY (`iid`), PRIMARY KEY (`iid`),
KEY `uid` (`uid`),
KEY `contact-id` (`contact-id`),
KEY `created` (`created`), KEY `created` (`created`),
KEY `edited` (`edited`),
KEY `commented` (`commented`), KEY `commented` (`commented`),
KEY `received` (`received`), KEY `uid_network_commented` (`uid`,`network`,`commented`),
KEY `changed` (`changed`), KEY `uid_network_created` (`uid`,`network`,`created`),
KEY `network` (`network`), KEY `uid_contactid_commented` (`uid`,`contact-id`,`commented`),
KEY `visible_deleted_moderated_private_wall_received` (`visible`,`deleted`,`moderated`,`private`,`wall`,`received`), KEY `uid_contactid_created` (`uid`,`contact-id`,`created`),
KEY `uid_visible_deleted_moderated_created` (`uid`,`visible`,`deleted`,`moderated`,`created`), KEY `wall_private_received` (`wall`,`private`,`received`),
KEY `uid_visible_deleted_moderated_commented` (`uid`,`visible`,`deleted`,`moderated`,`commented`) KEY `uid_created` (`uid`,`created`),
KEY `uid_commented` (`uid`,`commented`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8; ) ENGINE=MyISAM DEFAULT CHARSET=utf8;

View file

@ -386,7 +386,7 @@
//AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''", //AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''",
// count public wall messages // count public wall messages
$r = q("SELECT count(*) as `count` FROM `item` force index (uid_type) $r = q("SELECT count(*) as `count` FROM `item`
WHERE `uid` = %d WHERE `uid` = %d
AND `type`='wall'", AND `type`='wall'",
intval($uinfo[0]['uid']) intval($uinfo[0]['uid'])

View file

@ -6,6 +6,7 @@ require_once('include/salmon.php');
require_once('include/crypto.php'); require_once('include/crypto.php');
require_once('include/Photo.php'); require_once('include/Photo.php');
require_once('include/tags.php'); require_once('include/tags.php');
require_once('include/files.php');
require_once('include/text.php'); require_once('include/text.php');
require_once('include/email.php'); require_once('include/email.php');
require_once('include/ostatus_conversation.php'); require_once('include/ostatus_conversation.php');
@ -123,22 +124,25 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0)
$check_date = datetime_convert('UTC','UTC',$last_update,'Y-m-d H:i:s'); $check_date = datetime_convert('UTC','UTC',$last_update,'Y-m-d H:i:s');
// AND ( `item`.`edited` > '%s' OR `item`.`changed` > '%s' )
// dbesc($check_date),
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`, $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
`contact`.`name`, `contact`.`network`, `contact`.`photo`, `contact`.`url`, `contact`.`name`, `contact`.`network`, `contact`.`photo`, `contact`.`url`,
`contact`.`name-date`, `contact`.`uri-date`, `contact`.`avatar-date`, `contact`.`name-date`, `contact`.`uri-date`, `contact`.`avatar-date`,
`contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
`contact`.`id` AS `contact-id`, `contact`.`uid` AS `contact-uid`, `contact`.`id` AS `contact-id`, `contact`.`uid` AS `contact-uid`,
`sign`.`signed_text`, `sign`.`signature`, `sign`.`signer` `sign`.`signed_text`, `sign`.`signature`, `sign`.`signer`
FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid` FROM `item`
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id`
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`parent` != 0 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`parent` != 0
AND `item`.`wall` = 1 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `item`.`wall` = 1 AND `item`.`changed` > '%s'
AND ( `item`.`edited` > '%s' OR `item`.`changed` > '%s' )
$sql_extra $sql_extra
ORDER BY `parent` %s, `created` ASC LIMIT 0, 300", ORDER BY `parent` %s, `created` ASC LIMIT 0, 300",
intval($owner_id), intval($owner_id),
dbesc($check_date), dbesc($check_date),
dbesc($check_date),
dbesc($sort) dbesc($sort)
); );
@ -1161,7 +1165,6 @@ function item_store($arr,$force_parent = false) {
if(count($r)) { if(count($r)) {
$current_post = $r[0]['id']; $current_post = $r[0]['id'];
logger('item_store: created item ' . $current_post); logger('item_store: created item ' . $current_post);
create_tags_from_item($r[0]['id']);
// Only check for notifications on start posts // Only check for notifications on start posts
if ($arr['parent-uri'] === $arr['uri']) { if ($arr['parent-uri'] === $arr['uri']) {
@ -1240,7 +1243,6 @@ function item_store($arr,$force_parent = false) {
intval($parent_deleted), intval($parent_deleted),
intval($current_post) intval($current_post)
); );
create_tags_from_item($current_post);
// Complete ostatus threads // Complete ostatus threads
if ($ostatus_conversation) if ($ostatus_conversation)
@ -1307,14 +1309,17 @@ function item_store($arr,$force_parent = false) {
$r = q('SELECT * FROM `item` WHERE id = %d', intval($current_post)); $r = q('SELECT * FROM `item` WHERE id = %d', intval($current_post));
if (count($r) == 1) { if (count($r) == 1) {
call_hooks('post_remote_end', $r[0]); call_hooks('post_remote_end', $r[0]);
} } else {
else {
logger('item_store: new item not found in DB, id ' . $current_post); logger('item_store: new item not found in DB, id ' . $current_post);
} }
} }
create_tags_from_item($current_post);
create_files_from_item($current_post);
return $current_post; return $current_post;
} }
// return - test
function get_item_contact($item,$contacts) { function get_item_contact($item,$contacts) {
if(! count($contacts) || (! is_array($item))) if(! count($contacts) || (! is_array($item)))
return false; return false;
@ -2041,6 +2046,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
intval($importer['uid']) intval($importer['uid'])
); );
create_tags_from_itemuri($item['uri'], $importer['uid']); create_tags_from_itemuri($item['uri'], $importer['uid']);
create_files_from_itemuri($item['uri'], $importer['uid']);
update_thread_uri($item['uri'], $importer['uid']); update_thread_uri($item['uri'], $importer['uid']);
} }
else { else {
@ -2053,6 +2059,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
intval($importer['uid']) intval($importer['uid'])
); );
create_tags_from_itemuri($uri, $importer['uid']); create_tags_from_itemuri($uri, $importer['uid']);
create_files_from_itemuri($uri, $importer['uid']);
if($item['last-child']) { if($item['last-child']) {
// ensure that last-child is set in case the comment that had it just got wiped. // ensure that last-child is set in case the comment that had it just got wiped.
q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ", q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ",
@ -2159,11 +2166,12 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited']) if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited'])
continue; continue;
$r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d", $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s', `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d",
dbesc($datarray['title']), dbesc($datarray['title']),
dbesc($datarray['body']), dbesc($datarray['body']),
dbesc($datarray['tag']), dbesc($datarray['tag']),
dbesc(datetime_convert('UTC','UTC',$datarray['edited'])), dbesc(datetime_convert('UTC','UTC',$datarray['edited'])),
dbesc(datetime_convert()),
dbesc($item_id), dbesc($item_id),
intval($importer['uid']) intval($importer['uid'])
); );
@ -2319,11 +2327,12 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited']) if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited'])
continue; continue;
$r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d", $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s', `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d",
dbesc($datarray['title']), dbesc($datarray['title']),
dbesc($datarray['body']), dbesc($datarray['body']),
dbesc($datarray['tag']), dbesc($datarray['tag']),
dbesc(datetime_convert('UTC','UTC',$datarray['edited'])), dbesc(datetime_convert('UTC','UTC',$datarray['edited'])),
dbesc(datetime_convert()),
dbesc($item_id), dbesc($item_id),
intval($importer['uid']) intval($importer['uid'])
); );
@ -2948,6 +2957,7 @@ function local_delivery($importer,$data) {
intval($importer['importer_uid']) intval($importer['importer_uid'])
); );
create_tags_from_itemuri($item['uri'], $importer['importer_uid']); create_tags_from_itemuri($item['uri'], $importer['importer_uid']);
create_files_from_itemuri($item['uri'], $importer['importer_uid']);
update_thread_uri($item['uri'], $importer['importer_uid']); update_thread_uri($item['uri'], $importer['importer_uid']);
} }
else { else {
@ -2960,6 +2970,7 @@ function local_delivery($importer,$data) {
intval($importer['importer_uid']) intval($importer['importer_uid'])
); );
create_tags_from_itemuri($uri, $importer['importer_uid']); create_tags_from_itemuri($uri, $importer['importer_uid']);
create_files_from_itemuri($uri, $importer['importer_uid']);
update_thread_uri($uri, $importer['importer_uid']); update_thread_uri($uri, $importer['importer_uid']);
if($item['last-child']) { if($item['last-child']) {
// ensure that last-child is set in case the comment that had it just got wiped. // ensure that last-child is set in case the comment that had it just got wiped.
@ -3078,11 +3089,12 @@ function local_delivery($importer,$data) {
continue; continue;
logger('received updated comment' , LOGGER_DEBUG); logger('received updated comment' , LOGGER_DEBUG);
$r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d", $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s', `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d",
dbesc($datarray['title']), dbesc($datarray['title']),
dbesc($datarray['body']), dbesc($datarray['body']),
dbesc($datarray['tag']), dbesc($datarray['tag']),
dbesc(datetime_convert('UTC','UTC',$datarray['edited'])), dbesc(datetime_convert('UTC','UTC',$datarray['edited'])),
dbesc(datetime_convert()),
dbesc($item_id), dbesc($item_id),
intval($importer['importer_uid']) intval($importer['importer_uid'])
); );
@ -3164,9 +3176,10 @@ function local_delivery($importer,$data) {
intval($importer['importer_uid']) intval($importer['importer_uid'])
); );
if(count($i) && ! intval($i[0]['blocktags'])) { if(count($i) && ! intval($i[0]['blocktags'])) {
q("UPDATE item SET tag = '%s', `edited` = '%s' WHERE id = %d", q("UPDATE item SET tag = '%s', `edited` = '%s', `changed` = '%s' WHERE id = %d",
dbesc($tagp[0]['tag'] . (strlen($tagp[0]['tag']) ? ',' : '') . $newtag), dbesc($tagp[0]['tag'] . (strlen($tagp[0]['tag']) ? ',' : '') . $newtag),
intval($tagp[0]['id']), intval($tagp[0]['id']),
dbesc(datetime_convert()),
dbesc(datetime_convert()) dbesc(datetime_convert())
); );
create_tags_from_item($tagp[0]['id']); create_tags_from_item($tagp[0]['id']);
@ -3262,11 +3275,12 @@ function local_delivery($importer,$data) {
if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited']) if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited'])
continue; continue;
$r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d", $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s', `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d",
dbesc($datarray['title']), dbesc($datarray['title']),
dbesc($datarray['body']), dbesc($datarray['body']),
dbesc($datarray['tag']), dbesc($datarray['tag']),
dbesc(datetime_convert('UTC','UTC',$datarray['edited'])), dbesc(datetime_convert('UTC','UTC',$datarray['edited'])),
dbesc(datetime_convert()),
dbesc($item_id), dbesc($item_id),
intval($importer['importer_uid']) intval($importer['importer_uid'])
); );
@ -3447,11 +3461,12 @@ function local_delivery($importer,$data) {
if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited']) if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited'])
continue; continue;
$r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d", $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s', `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d",
dbesc($datarray['title']), dbesc($datarray['title']),
dbesc($datarray['body']), dbesc($datarray['body']),
dbesc($datarray['tag']), dbesc($datarray['tag']),
dbesc(datetime_convert('UTC','UTC',$datarray['edited'])), dbesc(datetime_convert('UTC','UTC',$datarray['edited'])),
dbesc(datetime_convert()),
dbesc($item_id), dbesc($item_id),
intval($importer['importer_uid']) intval($importer['importer_uid'])
); );
@ -4181,6 +4196,7 @@ function drop_item($id,$interactive = true) {
intval($item['id']) intval($item['id'])
); );
create_tags_from_item($item['id']); create_tags_from_item($item['id']);
create_files_from_item($item['id']);
delete_thread($item['id']); delete_thread($item['id']);
// clean up categories and tags so they don't end up as orphans // clean up categories and tags so they don't end up as orphans
@ -4276,6 +4292,7 @@ function drop_item($id,$interactive = true) {
intval($item['uid']) intval($item['uid'])
); );
create_tags_from_item($item['parent-uri'], $item['uid']); create_tags_from_item($item['parent-uri'], $item['uid']);
create_files_from_item($item['parent-uri'], $item['uid']);
delete_thread_uri($item['parent-uri'], $item['uid']); delete_thread_uri($item['parent-uri'], $item['uid']);
// ignore the result // ignore the result
} }

View file

@ -120,10 +120,12 @@ function display_content(&$a, $update = 0) {
$sql_extra = item_permissions_sql($a->profile['uid'],$remote_contact,$groups); $sql_extra = item_permissions_sql($a->profile['uid'],$remote_contact,$groups);
// AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' ))
if($update) { if($update) {
$r = q("SELECT id FROM item WHERE item.uid = %d $r = q("SELECT id FROM item WHERE item.uid = %d
AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' )) AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE (`id` = '%s' OR `uri` = '%s'))
$sql_extra AND unseen = 1", $sql_extra AND unseen = 1",
intval($a->profile['uid']), intval($a->profile['uid']),
dbesc($item_id), dbesc($item_id),
@ -134,6 +136,8 @@ function display_content(&$a, $update = 0) {
return ''; return '';
} }
// AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' )
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
`contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
@ -142,10 +146,10 @@ function display_content(&$a, $update = 0) {
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
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 `item`.`moderated` = 0 and `item`.`moderated` = 0
AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' ) AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE (`id` = '%s' OR `uri` = '%s')
AND uid = %d ) AND uid = %d)
$sql_extra $sql_extra
ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ", ORDER BY `parent` DESC, `gravity` ASC, `id` ASC",
intval($a->profile['uid']), intval($a->profile['uid']),
dbesc($item_id), dbesc($item_id),
dbesc($item_id), dbesc($item_id),
@ -162,6 +166,7 @@ function display_content(&$a, $update = 0) {
); );
if($r) { if($r) {
$item_uri = $r[0]['uri']; $item_uri = $r[0]['uri'];
// AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE `uri` = '%s' AND uid = %d )
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
@ -171,7 +176,7 @@ function display_content(&$a, $update = 0) {
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
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 `item`.`moderated` = 0 and `item`.`moderated` = 0
AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE `uri` = '%s' AND uid = %d ) AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `uri` = '%s' AND uid = %d)
ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ", ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
intval(local_user()), intval(local_user()),
dbesc($item_uri), dbesc($item_uri),

View file

@ -20,6 +20,7 @@ require_once('include/enotify.php');
require_once('include/email.php'); require_once('include/email.php');
require_once('library/langdet/Text/LanguageDetect.php'); require_once('library/langdet/Text/LanguageDetect.php');
require_once('include/tags.php'); require_once('include/tags.php');
require_once('include/files.php');
require_once('include/threads.php'); require_once('include/threads.php');
function item_post(&$a) { function item_post(&$a) {
@ -695,18 +696,17 @@ function item_post(&$a) {
if($orig_post) { if($orig_post) {
$r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `attach` = '%s', `file` = '%s', `edited` = '%s' WHERE `id` = %d AND `uid` = %d", $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `attach` = '%s', `file` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d",
dbesc($datarray['title']), dbesc($datarray['title']),
dbesc($datarray['body']), dbesc($datarray['body']),
dbesc($datarray['tag']), dbesc($datarray['tag']),
dbesc($datarray['attach']), dbesc($datarray['attach']),
dbesc($datarray['file']), dbesc($datarray['file']),
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc(datetime_convert()),
intval($post_id), intval($post_id),
intval($profile_uid) intval($profile_uid)
); );
create_tags_from_itemuri($post_id, $profile_uid);
update_thread_uri($post_id, $profile_uid);
// update filetags in pconfig // update filetags in pconfig
file_tag_update_pconfig($uid,$categories_old,$categories_new,'category'); file_tag_update_pconfig($uid,$categories_old,$categories_new,'category');
@ -773,7 +773,6 @@ function item_post(&$a) {
if(count($r)) { if(count($r)) {
$post_id = $r[0]['id']; $post_id = $r[0]['id'];
logger('mod_item: saved item ' . $post_id); logger('mod_item: saved item ' . $post_id);
create_tags_from_item($post_id);
add_thread($post_id); add_thread($post_id);
// update filetags in pconfig // update filetags in pconfig
@ -871,7 +870,6 @@ function item_post(&$a) {
dbesc(datetime_convert()), dbesc(datetime_convert()),
intval($post_id) intval($post_id)
); );
update_thread($post_id);
// photo comments turn the corresponding item visible to the profile wall // photo comments turn the corresponding item visible to the profile wall
// This way we don't see every picture in your new photo album posted to your wall at once. // This way we don't see every picture in your new photo album posted to your wall at once.
@ -939,6 +937,10 @@ function item_post(&$a) {
} }
} }
create_tags_from_item($post_id);
create_files_from_item($post_id);
update_thread($post_id);
// This is a real juggling act on shared hosting services which kill your processes // This is a real juggling act on shared hosting services which kill your processes
// e.g. dreamhost. We used to start delivery to our native delivery agents in the background // e.g. dreamhost. We used to start delivery to our native delivery agents in the background
// and then run our plugin delivery from the foreground. We're now doing plugin delivery first, // and then run our plugin delivery from the foreground. We're now doing plugin delivery first,

View file

@ -1,7 +1,7 @@
<?php <?php
/* /*
To-Do: To-Do:
- Community-Seite umstellen - Update berücksichtigt keine Konversationen
*/ */
function network_init(&$a) { function network_init(&$a) {
@ -579,6 +579,7 @@ die("ss");
$sql_extra3 = (($nouveau) ? '' : $sql_extra3); $sql_extra3 = (($nouveau) ? '' : $sql_extra3);
$sql_order = ""; $sql_order = "";
$order_mode = "received"; $order_mode = "received";
$tag = false;
if(x($_GET,'search')) { if(x($_GET,'search')) {
$search = escape_tags($_GET['search']); $search = escape_tags($_GET['search']);
@ -596,20 +597,26 @@ die("ss");
$sql_post_table = sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ", $sql_post_table = sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",
dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), intval(local_user())); dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), intval(local_user()));
$sql_order = "`item`.`id`";
$order_mode = "id";
} else { } else {
if (get_config('system','use_fulltext_engine')) if (get_config('system','use_fulltext_engine'))
$sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search))); $sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search)));
else else
$sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search)))); $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
}
$sql_order = "`item`.`received`"; $sql_order = "`item`.`received`";
$order_mode = "received"; $order_mode = "received";
} }
if(strlen($file)) }
$sql_extra .= file_tag_file_query('item',unxmlify($file)); if(strlen($file)) {
$sql_post_table = sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",
dbesc(protect_sprintf($file)), intval(TERM_OBJ_POST), intval(TERM_FILE), intval(local_user()));
$sql_order = "`item`.`id`";
$order_mode = "id";
}
if($conv) if($conv)
$sql_extra2 .= " AND `mention`"; $sql_extra3 .= " AND `mention`";
if($update) { if($update) {
@ -654,6 +661,9 @@ die("ss");
if($nouveau) { if($nouveau) {
$simple_update = (($update) ? " and `item`.`unseen` = 1 " : ''); $simple_update = (($update) ? " and `item`.`unseen` = 1 " : '');
if ($sql_order == "")
$sql_order = "`item`.`received`";
// "New Item View" - show all items unthreaded in reverse created date order // "New Item View" - show all items unthreaded in reverse created date order
$items = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, $items = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`, `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
@ -665,7 +675,7 @@ die("ss");
AND `item`.`deleted` = 0 and `item`.`moderated` = 0 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
$simple_update $simple_update
$sql_extra $sql_nets $sql_extra $sql_nets
ORDER BY `item`.`received` DESC $pager_sql ", ORDER BY $sql_order DESC $pager_sql ",
intval($_SESSION['uid']) intval($_SESSION['uid'])
); );

View file

@ -230,11 +230,13 @@ function profile_content(&$a, $update = 0) {
intval($a->profile['profile_uid']) intval($a->profile['profile_uid'])
); );
} } else {
else { $sql_post_table = "";
if(x($category)) { if(x($category)) {
$sql_extra .= protect_sprintf(file_tag_file_query('item',$category,'category')); $sql_post_table = sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",
dbesc(protect_sprintf($category)), intval(TERM_OBJ_POST), intval(TERM_CATEGORY), intval($a->profile['profile_uid']));
//$sql_extra .= protect_sprintf(file_tag_file_query('item',$category,'category'));
} }
if($datequery) { if($datequery) {
@ -247,7 +249,7 @@ function profile_content(&$a, $update = 0) {
if( (! get_config('alt_pager', 'global')) && (! get_pconfig($a->profile['profile_uid'],'system','alt_pager')) ) { if( (! get_config('alt_pager', 'global')) && (! get_pconfig($a->profile['profile_uid'],'system','alt_pager')) ) {
$r = q("SELECT COUNT(*) AS `total` $r = q("SELECT COUNT(*) AS `total`
FROM `thread` INNER JOIN `item` ON `item`.`id` = `thread`.`iid` FROM `thread` INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` $sql_post_table INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
WHERE `thread`.`uid` = %d AND `thread`.`visible` = 1 AND `thread`.`deleted` = 0 WHERE `thread`.`uid` = %d AND `thread`.`visible` = 1 AND `thread`.`deleted` = 0
and `thread`.`moderated` = 0 and `thread`.`moderated` = 0
@ -282,7 +284,7 @@ function profile_content(&$a, $update = 0) {
$r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`, $r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`,
`thread`.`uid` AS `contact-uid` `thread`.`uid` AS `contact-uid`
FROM `thread` INNER JOIN `item` ON `item`.`id` = `thread`.`iid` FROM `thread` INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` $sql_post_table INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
WHERE `thread`.`uid` = %d AND `thread`.`visible` = 1 AND `thread`.`deleted` = 0 WHERE `thread`.`uid` = %d AND `thread`.`visible` = 1 AND `thread`.`deleted` = 0
and `thread`.`moderated` = 0 and `thread`.`moderated` = 0
@ -310,7 +312,7 @@ function profile_content(&$a, $update = 0) {
FROM `item`, `contact` FROM `item`, `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 `item`.`moderated` = 0 and `item`.`moderated` = 0
AND `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid` 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` IN ( %s ) AND `item`.`parent` IN ( %s )
$sql_extra ", $sql_extra ",

View file

@ -128,17 +128,6 @@ function search_content(&$a) {
$tag = true; $tag = true;
if($tag) { if($tag) {
//$sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d",
//$sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d group by `item`.`uri` ",
// dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG));
//$sql_table = "`term` INNER JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` ";
//$sql_order = "`term`.`tid`";
//$sql_order = "`item`.`received`";
//$sql_extra = sprintf(" AND EXISTS (SELECT * FROM `term` WHERE `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d) GROUP BY `item`.`uri` ",
// dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG));
//$sql_table = "`item` FORCE INDEX (`uri`) ";
$sql_extra = ""; $sql_extra = "";
$sql_table = sprintf("`item` INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ", $sql_table = sprintf("`item` INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",

View file

@ -1562,7 +1562,7 @@ function update_1169() {
$r = q("CREATE TABLE IF NOT EXISTS `thread` ( $r = q("CREATE TABLE IF NOT EXISTS `thread` (
`iid` int(10) unsigned NOT NULL DEFAULT '0', `iid` int(10) unsigned NOT NULL DEFAULT '0',
`uid` int(10) unsigned NOT NULL DEFAULT '0', `uid` int(10) unsigned NOT NULL DEFAULT '0',
`contact-id` int(10) unsigned NOT NULL DEFAULT '0', `contact-id` int(11) unsigned NOT NULL DEFAULT '0',
`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', `commented` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
@ -1583,17 +1583,15 @@ function update_1169() {
`mention` tinyint(1) NOT NULL DEFAULT '0', `mention` tinyint(1) NOT NULL DEFAULT '0',
`network` char(32) NOT NULL, `network` char(32) NOT NULL,
PRIMARY KEY (`iid`), PRIMARY KEY (`iid`),
KEY `uid` (`uid`),
KEY `contact-id` (`contact-id`),
KEY `created` (`created`), KEY `created` (`created`),
KEY `edited` (`edited`),
KEY `commented` (`commented`), KEY `commented` (`commented`),
KEY `received` (`received`), KEY `uid_network_commented` (`uid`,`network`,`commented`),
KEY `changed` (`changed`), KEY `uid_network_created` (`uid`,`network`,`created`),
KEY `network` (`network`) KEY `uid_contactid_commented` (`uid`,`contact-id`,`commented`),
KEY `visible_deleted_moderated_private_wall_received` (`visible`,`deleted`,`moderated`,`private`,`wall`,`received`), KEY `uid_contactid_created` (`uid`,`contact-id`,`created`),
KEY `uid_visible_deleted_moderated_created` (`uid`,`visible`,`deleted`,`moderated`,`created`), KEY `wall_private_received` (`wall`,`private`,`received`),
KEY `uid_visible_deleted_moderated_commented` (`uid`,`visible`,`deleted`,`moderated`,`commented`) KEY `uid_created` (`uid`,`created`),
KEY `uid_commented` (`uid`,`commented`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;"); ) ENGINE=MyISAM DEFAULT CHARSET=utf8;");
if (!$r) if (!$r)
return UPDATE_FAILED; return UPDATE_FAILED;