Even more SQL improvements.

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

View file

@ -120,32 +120,36 @@ function display_content(&$a, $update = 0) {
$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) {
$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",
intval($a->profile['uid']),
dbesc($item_id),
dbesc($item_id)
dbesc($item_id)
);
if(!$r)
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`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
`contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
`contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
and `item`.`moderated` = 0
AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' )
AND uid = %d )
AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE (`id` = '%s' OR `uri` = '%s')
AND uid = %d)
$sql_extra
ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
ORDER BY `parent` DESC, `gravity` ASC, `id` ASC",
intval($a->profile['uid']),
dbesc($item_id),
dbesc($item_id),
@ -162,6 +166,7 @@ function display_content(&$a, $update = 0) {
);
if($r) {
$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`,
`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
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 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 ",
intval(local_user()),
dbesc($item_uri),
@ -184,7 +189,7 @@ function display_content(&$a, $update = 0) {
if($r) {
if((local_user()) && (local_user() == $a->profile['uid'])) {
q("UPDATE `item` SET `unseen` = 0
q("UPDATE `item` SET `unseen` = 0
WHERE `parent` = %d AND `unseen` = 1",
intval($r[0]['parent'])
);
@ -257,8 +262,8 @@ function display_content(&$a, $update = 0) {
if($r[0]['deleted']) {
notice( t('Item has been removed.') . EOL );
}
else {
notice( t('Permission denied.') . EOL );
else {
notice( t('Permission denied.') . EOL );
}
}
else {

View file

@ -20,6 +20,7 @@ require_once('include/enotify.php');
require_once('include/email.php');
require_once('library/langdet/Text/LanguageDetect.php');
require_once('include/tags.php');
require_once('include/files.php');
require_once('include/threads.php');
function item_post(&$a) {
@ -695,18 +696,17 @@ function item_post(&$a) {
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['body']),
dbesc($datarray['tag']),
dbesc($datarray['attach']),
dbesc($datarray['file']),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
intval($post_id),
intval($profile_uid)
);
create_tags_from_itemuri($post_id, $profile_uid);
update_thread_uri($post_id, $profile_uid);
// update filetags in pconfig
file_tag_update_pconfig($uid,$categories_old,$categories_new,'category');
@ -773,7 +773,6 @@ function item_post(&$a) {
if(count($r)) {
$post_id = $r[0]['id'];
logger('mod_item: saved item ' . $post_id);
create_tags_from_item($post_id);
add_thread($post_id);
// update filetags in pconfig
@ -871,7 +870,6 @@ function item_post(&$a) {
dbesc(datetime_convert()),
intval($post_id)
);
update_thread($post_id);
// 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.
@ -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
// 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,
@ -946,7 +948,7 @@ function item_post(&$a) {
// likely to get killed off. If you end up looking at an /item URL and a blank page,
// it's very likely the delivery got killed before all your friends could be notified.
// Currently the only realistic fixes are to use a reliable server - which precludes shared hosting,
// or cut back on plugins which do remote deliveries.
// or cut back on plugins which do remote deliveries.
proc_run('php', "include/notifier.php", $notify_type, "$post_id");

View file

@ -1,7 +1,7 @@
<?php
/*
To-Do:
- Community-Seite umstellen
- Update berücksichtigt keine Konversationen
*/
function network_init(&$a) {
@ -579,6 +579,7 @@ die("ss");
$sql_extra3 = (($nouveau) ? '' : $sql_extra3);
$sql_order = "";
$order_mode = "received";
$tag = false;
if(x($_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` ",
dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), intval(local_user()));
$sql_order = "`item`.`id`";
$order_mode = "id";
} else {
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)));
else
$sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
$sql_order = "`item`.`received`";
$order_mode = "received";
}
$sql_order = "`item`.`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)
$sql_extra2 .= " AND `mention`";
$sql_extra3 .= " AND `mention`";
if($update) {
@ -654,6 +661,9 @@ die("ss");
if($nouveau) {
$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
$items = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
@ -665,7 +675,7 @@ die("ss");
AND `item`.`deleted` = 0 and `item`.`moderated` = 0
$simple_update
$sql_extra $sql_nets
ORDER BY `item`.`received` DESC $pager_sql ",
ORDER BY $sql_order DESC $pager_sql ",
intval($_SESSION['uid'])
);

View file

@ -230,11 +230,13 @@ function profile_content(&$a, $update = 0) {
intval($a->profile['profile_uid'])
);
}
else {
} else {
$sql_post_table = "";
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) {
@ -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')) ) {
$r = q("SELECT COUNT(*) AS `total`
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
WHERE `thread`.`uid` = %d AND `thread`.`visible` = 1 AND `thread`.`deleted` = 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`,
`thread`.`uid` AS `contact-uid`
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
WHERE `thread`.`uid` = %d AND `thread`.`visible` = 1 AND `thread`.`deleted` = 0
and `thread`.`moderated` = 0
@ -310,7 +312,7 @@ function profile_content(&$a, $update = 0) {
FROM `item`, `contact`
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 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 `item`.`parent` IN ( %s )
$sql_extra ",

View file

@ -128,17 +128,6 @@ function search_content(&$a) {
$tag = true;
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_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` ",
@ -158,7 +147,7 @@ function search_content(&$a) {
// Here is the way permissions work in the search module...
// Only public posts can be shown
// OR your own posts if you are a logged in member
// No items will be shown if the member has a blocked profile wall.
// No items will be shown if the member has a blocked profile wall.
if( (! get_config('alt_pager', 'global')) && (! get_pconfig(local_user(),'system','alt_pager')) ) {
$r = q("SELECT distinct(`item`.`uri`) as `total`