The queries for items are unified (a little bit)

This commit is contained in:
Michael Vogel 2016-06-12 21:04:55 +02:00
parent 6d50d18242
commit c05898c57d
11 changed files with 132 additions and 110 deletions

View file

@ -1309,7 +1309,7 @@
$r = q("SELECT STRAIGHT_JOIN `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, $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`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
`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`
FROM `item`, `contact` FROM `item`, `contact`
WHERE `item`.`uid` = %d AND `verb` = '%s' WHERE `item`.`uid` = %d AND `verb` = '%s'
AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0 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`, $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`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`, `contact`.`id` AS `cid`,
`user`.`nickname`, `user`.`hidewall` `user`.`nickname`, `user`.`hidewall`
FROM `item` STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` FROM `item` STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
STRAIGHT_JOIN `user` ON `user`.`uid` = `item`.`uid` 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`, $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`.`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`
FROM `item`, `contact` FROM `item`, `contact`
WHERE `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0 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' 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`, $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`.`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`
FROM `item` FROM `item`
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `item`.`parent` = %d AND `item`.`visible` 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`, $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`.`name`, `contact`.`photo` as `reply_photo`, `contact`.`url` as `reply_url`, `contact`.`rel`,
`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`
FROM `item`, `contact` FROM `item`, `contact`
WHERE `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0 WHERE `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
AND `contact`.`id` = `item`.`contact-id` AND `contact`.`id` = `item`.`contact-id`
@ -1699,7 +1699,7 @@
$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`.`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`
FROM `item` FORCE INDEX (`uid_id`), `contact` FROM `item` FORCE INDEX (`uid_id`), `contact`
WHERE `item`.`uid` = %d AND `verb` = '%s' WHERE `item`.`uid` = %d AND `verb` = '%s'
AND NOT (`item`.`author-link` IN ('https://%s', 'http://%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`, $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`.`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`
FROM `item`, `contact` FROM `item`, `contact`
WHERE `item`.`uid` = %d AND `verb` = '%s' WHERE `item`.`uid` = %d AND `verb` = '%s'
AND `item`.`contact-id` = %d AND `item`.`contact-id` = %d
@ -1904,7 +1904,7 @@
$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`.`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`
FROM `item`, `contact` FROM `item`, `contact`
WHERE `item`.`uid` = %d WHERE `item`.`uid` = %d
AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0 AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0

View file

@ -373,6 +373,55 @@ function visible_activity($item) {
return true; 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. * "Render" a conversation or list of items for HTML display.

View file

@ -197,7 +197,6 @@ class dfrn {
`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`,
`sign`.`signed_text`, `sign`.`signature`, `sign`.`signer` `sign`.`signed_text`, `sign`.`signature`, `sign`.`signer`
FROM `item` $sql_post_table FROM `item` $sql_post_table
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`

View file

@ -114,7 +114,9 @@ load_translation_table($lang);
* *
*/ */
$stamp1 = microtime(true);
session_start(); session_start();
$a->save_timestamp($stamp1, "parser");
/** /**
* Language was set earlier, but we can over-ride it in the session. * Language was set earlier, but we can over-ride it in the session.

View file

@ -120,23 +120,20 @@ function community_getitems($start, $itemspage) {
if (get_config('system','community_page_style') == CP_GLOBAL_COMMUNITY) if (get_config('system','community_page_style') == CP_GLOBAL_COMMUNITY)
return(community_getpublicitems($start, $itemspage)); return(community_getpublicitems($start, $itemspage));
$r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`, $r = q("SELECT %s, %s, `user`.`nickname`
`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`
FROM `thread` FORCE INDEX (`wall_private_received`) 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` INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`self` AND %s AND `contact`.`self`
WHERE `thread`.`visible` = 1 AND `thread`.`deleted` = 0 and `thread`.`moderated` = 0 WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
AND `thread`.`private` = 0 AND `thread`.`wall` = 1 AND NOT `thread`.`private` AND `thread`.`wall`
ORDER BY `thread`.`received` DESC LIMIT %d, %d", ORDER BY `thread`.`received` DESC LIMIT %d, %d",
intval($start), item_fieldlist(), contact_fieldlist(),
intval($itemspage) contact_condition(),
intval($start), intval($itemspage)
); );
return($r); return($r);
@ -144,14 +141,14 @@ function community_getitems($start, $itemspage) {
} }
function community_getpublicitems($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` `owner-link` AS `url`, `owner-avatar` AS `thumb`
FROM `thread` FROM `thread`
INNER JOIN `item` ON `item`.`id` = `thread`.`iid` INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
WHERE `thread`.`uid` = 0 WHERE `thread`.`uid` = 0
ORDER BY `thread`.`created` DESC LIMIT %d, %d", ORDER BY `thread`.`created` DESC LIMIT %d, %d",
intval($start), item_fieldlist(), intval($start),
intval($itemspage) intval($itemspage)
); );

View file

@ -217,7 +217,7 @@ function content_content(&$a, $update = 0) {
$items = q("SELECT `item`.*, `item`.`id` AS `item_id`, $items = 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`
FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 WHERE `item`.`uid` = %d AND `item`.`visible` = 1
AND `item`.`deleted` = 0 and `item`.`moderated` = 0 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`, $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`, `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `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`
FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` FROM $sql_table INNER 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 `item`.`moderated` = 0 AND `item`.`moderated` = 0

View file

@ -362,17 +362,14 @@ function display_content(&$a, $update = 0) {
return ''; return '';
} }
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, $r = q("SELECT %s, %s FROM `item`
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s
`contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, WHERE %s AND `item`.`uid` = %d
`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`
AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `id` = %d) AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `id` = %d)
$sql_extra $sql_extra
ORDER BY `parent` DESC, `gravity` ASC, `id` ASC", ORDER BY `parent` DESC, `gravity` ASC, `id` ASC",
item_fieldlist(), contact_fieldlist(),
contact_condition(), item_condition(),
intval($a->profile['uid']), intval($a->profile['uid']),
intval($item_id) intval($item_id)
); );
@ -388,16 +385,13 @@ function display_content(&$a, $update = 0) {
if($r) { if($r) {
$item_uri = $r[0]['uri']; $item_uri = $r[0]['uri'];
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, $r = q("SELECT %s, %s FROM `item`
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s
`contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, WHERE %s AND `item`.`uid` = %d
`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`
AND `item`.`parent` = (SELECT `parent` FROM `item` 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 ",
item_fieldlist(), contact_fieldlist(),
contact_condition(), item_condition(),
intval(local_user()), intval(local_user()),
dbesc($item_uri), dbesc($item_uri),
intval(local_user()) intval(local_user())

View file

@ -720,17 +720,14 @@ function network_content(&$a, $update = 0) {
$sql_order = "`item`.`received`"; $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 %s, %s FROM $sql_table $sql_post_table
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`, INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, WHERE %s AND `item`.`uid` = %d
`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
$simple_update $simple_update
$sql_extra $sql_nets $sql_extra $sql_nets
ORDER BY $sql_order DESC $pager_sql ", ORDER BY $sql_order DESC $pager_sql ",
item_fieldlist(), contact_fieldlist(),
contact_condition(), item_condition(),
intval($_SESSION['uid']) intval($_SESSION['uid'])
); );
@ -810,16 +807,13 @@ function network_content(&$a, $update = 0) {
foreach ($parents_arr AS $parents) { foreach ($parents_arr AS $parents) {
// $sql_extra ORDER BY `item`.`commented` DESC LIMIT %d", // $sql_extra ORDER BY `item`.`commented` DESC LIMIT %d",
$thread_items = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, $thread_items = q("SELECT %s, %s FROM `item`
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`, INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, WHERE %s AND `item`.`uid` = %d
`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` = %d AND `item`.`parent` = %d
ORDER BY `item`.`commented` DESC LIMIT %d", ORDER BY `item`.`commented` DESC LIMIT %d",
item_fieldlist(), contact_fieldlist(),
contact_condition(), item_condition(),
intval(local_user()), intval(local_user()),
intval($parents), intval($parents),
intval($max_comments + 1) intval($max_comments + 1)

View file

@ -73,12 +73,11 @@ function notes_content(&$a,$update = false) {
$sql_extra = " AND `allow_cid` = '<" . $a->contact['id'] . ">' "; $sql_extra = " AND `allow_cid` = '<" . $a->contact['id'] . ">' ";
$r = q("SELECT COUNT(*) AS `total` $r = q("SELECT COUNT(*) AS `total`
FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 and `item`.`moderated` = 0 WHERE %s AND `item`.`uid` = %d AND `item`.`type` = 'note'
AND `item`.`deleted` = 0 AND `item`.`type` = 'note' AND `contact`.`self` AND `item`.`id` = `item`.`parent` AND NOT `item`.`wall`
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`self` = 1
AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 0
$sql_extra ", $sql_extra ",
contact_condition(), item_condition(),
intval(local_user()) intval(local_user())
); );
@ -88,14 +87,13 @@ function notes_content(&$a,$update = false) {
$a->set_pager_itemspage(40); $a->set_pager_itemspage(40);
} }
$r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact-uid` $r = q("SELECT `item`.`id` AS `item_id` FROM `item`
FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s AND `contact`.`self`
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 WHERE %s AND `item`.`uid` = %d AND `item`.`type` = 'note'
and `item`.`moderated` = 0 AND `item`.`type` = 'note' AND `item`.`id` = `item`.`parent` AND NOT `item`.`wall`
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`self` = 1
AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 0
$sql_extra $sql_extra
ORDER BY `item`.`created` DESC LIMIT %d ,%d ", ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
contact_condition(), item_condition(),
intval(local_user()), intval(local_user()),
intval($a->pager['start']), intval($a->pager['start']),
intval($a->pager['itemspage']) intval($a->pager['itemspage'])
@ -110,16 +108,13 @@ function notes_content(&$a,$update = false) {
$parents_arr[] = $rr['item_id']; $parents_arr[] = $rr['item_id'];
$parents_str = implode(', ', $parents_arr); $parents_str = implode(', ', $parents_arr);
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`, $r = q("SELECT %s, %s FROM `item`
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`network`, `contact`.`rel`, LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s
`contact`.`thumb`, `contact`.`self`, `contact`.`writable`, WHERE %s AND `item`.`uid` = %d AND `item`.`parent` IN (%s)
`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 )
$sql_extra $sql_extra
ORDER BY `parent` DESC, `gravity` ASC, `item`.`id` ASC ", ORDER BY `parent` DESC, `gravity` ASC, `item`.`id` ASC ",
item_fieldlist(), contact_fieldlist(),
contact_condition(), item_condition(),
intval(local_user()), intval(local_user()),
dbesc($parents_str) dbesc($parents_str)
); );

View file

@ -216,8 +216,7 @@ function profile_content(&$a, $update = 0) {
if($update) { if($update) {
$r = q("SELECT distinct(parent) AS `item_id`, `item`.`network` AS `item_network`, $r = q("SELECT distinct(parent) AS `item_id`, `item`.`network` AS `item_network`
`contact`.`uid` AS `contact-uid`
FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
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 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'])); $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`, $r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`
`thread`.`uid` AS `contact-uid`
FROM `thread` FORCE INDEX (`uid_created`) INNER JOIN `item` ON `item`.`id` = `thread`.`iid` 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` $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
@ -305,17 +303,13 @@ function profile_content(&$a, $update = 0) {
$parents_arr[] = $rr['item_id']; $parents_arr[] = $rr['item_id'];
$parents_str = implode(', ', $parents_arr); $parents_str = implode(', ', $parents_arr);
$items = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, $items = q("SELECT %s, %s FROM `item`
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`network`, `contact`.`rel`, INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s
`contact`.`thumb`, `contact`.`self`, `contact`.`writable`, WHERE %s AND `item`.`uid` = %d
`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) AND `item`.`parent` IN (%s)
$sql_extra ", $sql_extra ",
item_fieldlist(), contact_fieldlist(),
contact_condition(), item_condition(),
intval($a->profile['profile_uid']), intval($a->profile['profile_uid']),
dbesc($parents_str) dbesc($parents_str)
); );

View file

@ -191,17 +191,16 @@ function search_content(&$a) {
if($tag) { if($tag) {
logger("Start tag search for '".$search."'", LOGGER_DEBUG); logger("Start tag search for '".$search."'", LOGGER_DEBUG);
$r = q("SELECT STRAIGHT_JOIN `item`.`uri`, `item`.*, `item`.`id` AS `item_id`, $r = q("SELECT STRAIGHT_JOIN %s, %s
`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`
FROM `term` FROM `term`
INNER JOIN `item` ON `item`.`id`=`term`.`oid` 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` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s
WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated` 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'
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 ", 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'])); intval($a->pager['start']), intval($a->pager['itemspage']));
} else { } else {
logger("Start fulltext search for '".$search."'", LOGGER_DEBUG); 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)))); $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`, $r = q("SELECT STRAIGHT_JOIN %s, %s
`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`
FROM `item` FROM `item`
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND NOT `contact`.`blocked` AND NOT `contact`.`pending` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s
WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated` WHERE %s AND (`item`.`uid` = 0 OR (`item`.`uid` = %s AND NOT `item`.`global`))
AND (`item`.`uid` = 0 OR (`item`.`uid` = %s AND NOT `item`.`global`))
$sql_extra $sql_extra
GROUP BY `item`.`uri` ORDER BY `item`.`id` DESC LIMIT %d , %d", GROUP BY `item`.`uri` ORDER BY `item`.`id` DESC LIMIT %d , %d",
intval(local_user()), intval($a->pager['start']), intval($a->pager['itemspage'])); item_fieldlist(), contact_fieldlist(),
contact_condition(), item_condition(),
intval(local_user()),
intval($a->pager['start']), intval($a->pager['itemspage']));
} }
if(! count($r)) { if(! count($r)) {