From c05898c57d8aca254944c1de553360fb3aeee319 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 12 Jun 2016 21:04:55 +0200 Subject: [PATCH] The queries for items are unified (a little bit) --- include/api.php | 16 ++++++------- include/conversation.php | 49 ++++++++++++++++++++++++++++++++++++++++ include/dfrn.php | 1 - index.php | 2 ++ mod/community.php | 27 ++++++++++------------ mod/content.php | 4 ++-- mod/display.php | 26 ++++++++------------- mod/network.php | 26 ++++++++------------- mod/notes.php | 37 +++++++++++++----------------- mod/profile.php | 22 +++++++----------- mod/search.php | 32 ++++++++++++-------------- 11 files changed, 132 insertions(+), 110 deletions(-) diff --git a/include/api.php b/include/api.php index f32dc97c6..c86a3cbe4 100644 --- a/include/api.php +++ b/include/api.php @@ -1309,7 +1309,7 @@ $r = q("SELECT STRAIGHT_JOIN `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, - `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` + `contact`.`id` AS `cid` FROM `item`, `contact` WHERE `item`.`uid` = %d AND `verb` = '%s' AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0 @@ -1388,7 +1388,7 @@ $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`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`, + `contact`.`id` AS `cid`, `user`.`nickname`, `user`.`hidewall` FROM `item` STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` STRAIGHT_JOIN `user` ON `user`.`uid` = `item`.`uid` @@ -1457,7 +1457,7 @@ $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`.`dfrn-id`, `contact`.`self`, - `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` + `contact`.`id` AS `cid` FROM `item`, `contact` WHERE `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0 AND `contact`.`id` = `item`.`contact-id` AND `item`.`uid` = %d AND `item`.`verb` = '%s' @@ -1534,7 +1534,7 @@ $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`.`dfrn-id`, `contact`.`self`, - `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` + `contact`.`id` AS `cid` FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` WHERE `item`.`parent` = %d AND `item`.`visible` @@ -1586,7 +1586,7 @@ $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`nick` as `reply_author`, `contact`.`name`, `contact`.`photo` as `reply_photo`, `contact`.`url` as `reply_url`, `contact`.`rel`, `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, - `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` + `contact`.`id` AS `cid` FROM `item`, `contact` WHERE `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0 AND `contact`.`id` = `item`.`contact-id` @@ -1699,7 +1699,7 @@ $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`.`dfrn-id`, `contact`.`self`, - `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` + `contact`.`id` AS `cid` FROM `item` FORCE INDEX (`uid_id`), `contact` WHERE `item`.`uid` = %d AND `verb` = '%s' AND NOT (`item`.`author-link` IN ('https://%s', 'http://%s')) @@ -1776,7 +1776,7 @@ $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`.`dfrn-id`, `contact`.`self`, - `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` + `contact`.`id` AS `cid` FROM `item`, `contact` WHERE `item`.`uid` = %d AND `verb` = '%s' AND `item`.`contact-id` = %d @@ -1904,7 +1904,7 @@ $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`.`dfrn-id`, `contact`.`self`, - `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` + `contact`.`id` AS `cid` FROM `item`, `contact` WHERE `item`.`uid` = %d AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0 diff --git a/include/conversation.php b/include/conversation.php index 38f6e7686..ac0bd69e4 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -373,6 +373,55 @@ function visible_activity($item) { return true; } +/** + * @brief List of all contact fields that are needed for the conversation function + */ +function contact_fieldlist() { + + $fieldlist = "`contact`.`network`, `contact`.`url`, `contact`.`name`, `contact`.`writable`, + `contact`.`self`, `contact`.`id` AS `cid`, `contact`.`alias`"; + + return $fieldlist; +} + +/** + * @brief SQL condition for contacts + */ +function contact_condition() { + + $condition = "NOT `contact`.`blocked` AND NOT `contact`.`pending`"; + + return $condition; +} + +/** + * @brief SQL condition for items + */ +function item_condition() { + + $condition = "`item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`"; + + return $condition; +} + +/** + * @brief List of all item fields that are needed for the conversation function + */ +function item_fieldlist() { + + $fieldlist = "`item`.`author-link`, `item`.`verb`, `item`.`id`, `item`.`parent`, + `item`.`uid`, `item`.`author-name`, `item`.`tag`, `item`.`location`, `item`.`coord`, + `item`.`title`, `item`.`uri`, `item`.`created`, `item`.`app`, `item`.`guid`, + `item`.`contact-id`, `item`.`thr-parent`, `item`.`parent-uri`, `item`.`rendered-hash`, + `item`.`body`, `item`.`rendered-html`, `item`.`private`, `item`.`edited`, + `item`.`allow_cid`, `item`.`allow_gid`, `item`.`deny_cid`, `item`.`deny_gid`, + `item`.`event-id`, `item`.`object-type`, `item`.`starred`, `item`.`created`, + `item`.`postopts`, `item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`, + `item`.`plink`, `item`.`wall`, + `item`.`id` AS `item_id`, `item`.`network` AS `item_network`"; + + return $fieldlist; +} /** * "Render" a conversation or list of items for HTML display. diff --git a/include/dfrn.php b/include/dfrn.php index a974056e6..2dca1522c 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -197,7 +197,6 @@ class dfrn { `contact`.`name`, `contact`.`network`, `contact`.`photo`, `contact`.`url`, `contact`.`name-date`, `contact`.`uri-date`, `contact`.`avatar-date`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, - `contact`.`id` AS `contact-id`, `contact`.`uid` AS `contact-uid`, `sign`.`signed_text`, `sign`.`signature`, `sign`.`signer` FROM `item` $sql_post_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` diff --git a/index.php b/index.php index bf4ee378a..943763a51 100644 --- a/index.php +++ b/index.php @@ -114,7 +114,9 @@ load_translation_table($lang); * */ +$stamp1 = microtime(true); session_start(); +$a->save_timestamp($stamp1, "parser"); /** * Language was set earlier, but we can over-ride it in the session. diff --git a/mod/community.php b/mod/community.php index b6d72a355..a83bd39ec 100644 --- a/mod/community.php +++ b/mod/community.php @@ -120,23 +120,20 @@ function community_getitems($start, $itemspage) { if (get_config('system','community_page_style') == CP_GLOBAL_COMMUNITY) return(community_getpublicitems($start, $itemspage)); - $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`, - `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, - `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, - `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`, - `user`.`nickname`, `user`.`hidewall` + $r = q("SELECT %s, %s, `user`.`nickname` FROM `thread` FORCE INDEX (`wall_private_received`) - INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND `user`.`hidewall` = 0 + INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND NOT `user`.`hidewall` INNER JOIN `item` ON `item`.`id` = `thread`.`iid` AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` - AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`self` - WHERE `thread`.`visible` = 1 AND `thread`.`deleted` = 0 and `thread`.`moderated` = 0 - AND `thread`.`private` = 0 AND `thread`.`wall` = 1 - ORDER BY `thread`.`received` DESC LIMIT %d, %d ", - intval($start), - intval($itemspage) + AND %s AND `contact`.`self` + WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated` + AND NOT `thread`.`private` AND `thread`.`wall` + ORDER BY `thread`.`received` DESC LIMIT %d, %d", + item_fieldlist(), contact_fieldlist(), + contact_condition(), + intval($start), intval($itemspage) ); return($r); @@ -144,14 +141,14 @@ function community_getitems($start, $itemspage) { } function community_getpublicitems($start, $itemspage) { - $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`, - `author-name` AS `name`, `owner-avatar` AS `photo`, + + $r = q("SELECT %s, `author-name` AS `name`, `owner-avatar` AS `photo`, `owner-link` AS `url`, `owner-avatar` AS `thumb` FROM `thread` INNER JOIN `item` ON `item`.`id` = `thread`.`iid` WHERE `thread`.`uid` = 0 ORDER BY `thread`.`created` DESC LIMIT %d, %d", - intval($start), + item_fieldlist(), intval($start), intval($itemspage) ); diff --git a/mod/content.php b/mod/content.php index 1f373b80e..54d499d40 100644 --- a/mod/content.php +++ b/mod/content.php @@ -217,7 +217,7 @@ function content_content(&$a, $update = 0) { $items = 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` + `contact`.`id` AS `cid` FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 @@ -268,7 +268,7 @@ function content_content(&$a, $update = 0) { $items = q("SELECT `item`.*, `item`.`id` AS `item_id`, `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`, `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, - `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` + `contact`.`id` AS `cid` FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 AND `item`.`moderated` = 0 diff --git a/mod/display.php b/mod/display.php index 949ba5ab4..4ee26b740 100644 --- a/mod/display.php +++ b/mod/display.php @@ -362,17 +362,14 @@ function display_content(&$a, $update = 0) { return ''; } - $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`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` - FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - AND NOT `contact`.`blocked` AND NOT `contact`.`pending` - WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` - AND NOT `item`.`moderated` + $r = q("SELECT %s, %s FROM `item` + INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s + WHERE %s AND `item`.`uid` = %d AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `id` = %d) $sql_extra ORDER BY `parent` DESC, `gravity` ASC, `id` ASC", + item_fieldlist(), contact_fieldlist(), + contact_condition(), item_condition(), intval($a->profile['uid']), intval($item_id) ); @@ -388,16 +385,13 @@ function display_content(&$a, $update = 0) { if($r) { $item_uri = $r[0]['uri']; - $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`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` - FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - AND NOT `contact`.`blocked` AND NOT `contact`.`pending` - WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` - AND NOT `item`.`moderated` + $r = q("SELECT %s, %s FROM `item` + INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s + WHERE %s AND `item`.`uid` = %d AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `uri` = '%s' AND uid = %d) ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ", + item_fieldlist(), contact_fieldlist(), + contact_condition(), item_condition(), intval(local_user()), dbesc($item_uri), intval(local_user()) diff --git a/mod/network.php b/mod/network.php index 2dc63edb4..ba97b4a4c 100644 --- a/mod/network.php +++ b/mod/network.php @@ -720,17 +720,14 @@ function network_content(&$a, $update = 0) { $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`, - `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, - `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` - FROM $sql_table $sql_post_table 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 + $items = q("SELECT %s, %s FROM $sql_table $sql_post_table + INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s + WHERE %s AND `item`.`uid` = %d $simple_update $sql_extra $sql_nets ORDER BY $sql_order DESC $pager_sql ", + item_fieldlist(), contact_fieldlist(), + contact_condition(), item_condition(), intval($_SESSION['uid']) ); @@ -810,16 +807,13 @@ function network_content(&$a, $update = 0) { foreach ($parents_arr AS $parents) { // $sql_extra ORDER BY `item`.`commented` DESC LIMIT %d", - $thread_items = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, - `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`, - `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, - `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 + $thread_items = q("SELECT %s, %s FROM `item` + INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s + WHERE %s AND `item`.`uid` = %d AND `item`.`parent` = %d ORDER BY `item`.`commented` DESC LIMIT %d", + item_fieldlist(), contact_fieldlist(), + contact_condition(), item_condition(), intval(local_user()), intval($parents), intval($max_comments + 1) diff --git a/mod/notes.php b/mod/notes.php index 73c1507e3..8d93fc13d 100644 --- a/mod/notes.php +++ b/mod/notes.php @@ -69,16 +69,15 @@ function notes_content(&$a,$update = false) { // Construct permissions // default permissions - anonymous user - + $sql_extra = " AND `allow_cid` = '<" . $a->contact['id'] . ">' "; $r = q("SELECT COUNT(*) AS `total` - FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - WHERE `item`.`uid` = %d AND `item`.`visible` = 1 and `item`.`moderated` = 0 - AND `item`.`deleted` = 0 AND `item`.`type` = 'note' - AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`self` = 1 - AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 0 + FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s + WHERE %s AND `item`.`uid` = %d AND `item`.`type` = 'note' + AND `contact`.`self` AND `item`.`id` = `item`.`parent` AND NOT `item`.`wall` $sql_extra ", + contact_condition(), item_condition(), intval(local_user()) ); @@ -88,14 +87,13 @@ function notes_content(&$a,$update = false) { $a->set_pager_itemspage(40); } - $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 `item`.`moderated` = 0 AND `item`.`type` = 'note' - AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`self` = 1 - AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 0 + $r = q("SELECT `item`.`id` AS `item_id` FROM `item` + LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s AND `contact`.`self` + WHERE %s AND `item`.`uid` = %d AND `item`.`type` = 'note' + AND `item`.`id` = `item`.`parent` AND NOT `item`.`wall` $sql_extra ORDER BY `item`.`created` DESC LIMIT %d ,%d ", + contact_condition(), item_condition(), intval(local_user()), intval($a->pager['start']), intval($a->pager['itemspage']) @@ -109,17 +107,14 @@ function notes_content(&$a,$update = false) { foreach($r as $rr) $parents_arr[] = $rr['item_id']; $parents_str = implode(', ', $parents_arr); - - $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, - `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`network`, `contact`.`rel`, - `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, - `contact`.`id` AS `cid`, `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`.`moderated` = 0 AND `item`.`deleted` = 0 - AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 - AND `item`.`parent` IN ( %s ) + + $r = q("SELECT %s, %s FROM `item` + LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s + WHERE %s AND `item`.`uid` = %d AND `item`.`parent` IN (%s) $sql_extra ORDER BY `parent` DESC, `gravity` ASC, `item`.`id` ASC ", + item_fieldlist(), contact_fieldlist(), + contact_condition(), item_condition(), intval(local_user()), dbesc($parents_str) ); diff --git a/mod/profile.php b/mod/profile.php index 58e3a1607..88de0227b 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -216,8 +216,7 @@ function profile_content(&$a, $update = 0) { if($update) { - $r = q("SELECT distinct(parent) AS `item_id`, `item`.`network` AS `item_network`, - `contact`.`uid` AS `contact-uid` + $r = q("SELECT distinct(parent) AS `item_id`, `item`.`network` AS `item_network` 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 @@ -282,8 +281,7 @@ function profile_content(&$a, $update = 0) { $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage'])); - $r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`, - `thread`.`uid` AS `contact-uid` + $r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network` FROM `thread` FORCE INDEX (`uid_created`) INNER JOIN `item` ON `item`.`id` = `thread`.`iid` $sql_post_table INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 @@ -305,17 +303,13 @@ function profile_content(&$a, $update = 0) { $parents_arr[] = $rr['item_id']; $parents_str = implode(', ', $parents_arr); - $items = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, - `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`network`, `contact`.`rel`, - `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, - `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` - 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`.`blocked` = 0 AND `contact`.`pending` = 0 - AND `item`.`parent` IN ( %s ) + $items = q("SELECT %s, %s FROM `item` + INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s + WHERE %s AND `item`.`uid` = %d + AND `item`.`parent` IN (%s) $sql_extra ", + item_fieldlist(), contact_fieldlist(), + contact_condition(), item_condition(), intval($a->profile['profile_uid']), dbesc($parents_str) ); diff --git a/mod/search.php b/mod/search.php index 91c345b92..99ec6c5f7 100644 --- a/mod/search.php +++ b/mod/search.php @@ -191,17 +191,16 @@ function search_content(&$a) { if($tag) { logger("Start tag search for '".$search."'", LOGGER_DEBUG); - $r = q("SELECT STRAIGHT_JOIN `item`.`uri`, `item`.*, `item`.`id` AS `item_id`, - `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, - `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, - `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` + $r = q("SELECT STRAIGHT_JOIN %s, %s FROM `term` INNER JOIN `item` ON `item`.`id`=`term`.`oid` - INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND NOT `contact`.`blocked` AND NOT `contact`.`pending` - WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated` - AND (`term`.`uid` = 0 OR (`term`.`uid` = %d AND NOT `term`.`global`)) AND `term`.`otype` = %d AND `term`.`type` = %d AND `term`.`term` = '%s' + INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s + WHERE %s AND (`term`.`uid` = 0 OR (`term`.`uid` = %d AND NOT `term`.`global`)) AND `term`.`otype` = %d AND `term`.`type` = %d AND `term`.`term` = '%s' ORDER BY term.created DESC LIMIT %d , %d ", - intval(local_user()), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), dbesc(protect_sprintf($search)), + item_fieldlist(), contact_fieldlist(), + contact_condition(), item_condition(), + intval(local_user()), + intval(TERM_OBJ_POST), intval(TERM_HASHTAG), dbesc(protect_sprintf($search)), intval($a->pager['start']), intval($a->pager['itemspage'])); } else { logger("Start fulltext search for '".$search."'", LOGGER_DEBUG); @@ -212,17 +211,16 @@ function search_content(&$a) { $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search)))); } - $r = q("SELECT STRAIGHT_JOIN `item`.`uri`, `item`.*, `item`.`id` AS `item_id`, - `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, - `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, - `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` + $r = q("SELECT STRAIGHT_JOIN %s, %s FROM `item` - INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND NOT `contact`.`blocked` AND NOT `contact`.`pending` - WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated` - AND (`item`.`uid` = 0 OR (`item`.`uid` = %s AND NOT `item`.`global`)) + INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s + WHERE %s AND (`item`.`uid` = 0 OR (`item`.`uid` = %s AND NOT `item`.`global`)) $sql_extra - GROUP BY `item`.`uri` ORDER BY `item`.`id` DESC LIMIT %d , %d ", - intval(local_user()), intval($a->pager['start']), intval($a->pager['itemspage'])); + GROUP BY `item`.`uri` ORDER BY `item`.`id` DESC LIMIT %d , %d", + item_fieldlist(), contact_fieldlist(), + contact_condition(), item_condition(), + intval(local_user()), + intval($a->pager['start']), intval($a->pager['itemspage'])); } if(! count($r)) {