Optimised the amount of function for the item query
This commit is contained in:
parent
c3ed6f7d01
commit
91db7a549c
3 changed files with 40 additions and 91 deletions
|
@ -383,68 +383,10 @@ function item_query() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief All fieldlists that are needed for the item query
|
* @brief List of all data fields that are needed for displaying items
|
||||||
*/
|
*/
|
||||||
function item_fieldlists() {
|
function item_fieldlists() {
|
||||||
|
|
||||||
return item_fieldlist().", ".zcontact_fieldlist().", ".contact_fieldlist();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief SQL join for contacts
|
|
||||||
*/
|
|
||||||
function item_joins() {
|
|
||||||
|
|
||||||
return contact_join()." ".zcontact_join();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Fieldlist for author and owner
|
|
||||||
*/
|
|
||||||
function zcontact_fieldlist() {
|
|
||||||
|
|
||||||
return "`author`.`thumb` AS `author-thumb`, `owner`.`thumb` AS `owner-thumb`";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Join for author and owner
|
|
||||||
*/
|
|
||||||
function zcontact_join() {
|
|
||||||
|
|
||||||
return "LEFT JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id`
|
|
||||||
LEFT JOIN `contact` AS `owner` ON `owner`.`id`=`item`.`author-id`";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief List of all contact fields that are needed for the conversation function
|
|
||||||
*/
|
|
||||||
function contact_fieldlist() {
|
|
||||||
|
|
||||||
return "`contact`.`network`, `contact`.`url`, `contact`.`name`, `contact`.`writable`,
|
|
||||||
`contact`.`self`, `contact`.`id` AS `cid`, `contact`.`alias`";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief SQL condition for contacts
|
|
||||||
*/
|
|
||||||
function contact_condition() {
|
|
||||||
|
|
||||||
return "NOT `contact`.`blocked` AND NOT `contact`.`pending`";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief SQL join for contacts
|
|
||||||
*/
|
|
||||||
function contact_join() {
|
|
||||||
|
|
||||||
return "INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND ".contact_condition();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief List of all item fields that are needed for the conversation function
|
|
||||||
*/
|
|
||||||
function item_fieldlist() {
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
These Fields are not added below (yet). They are here to for bug search.
|
These Fields are not added below (yet). They are here to for bug search.
|
||||||
`item`.`type`,
|
`item`.`type`,
|
||||||
|
@ -475,21 +417,37 @@ These Fields are not added below (yet). They are here to for bug search.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return "`item`.`author-link`, `item`.`author-name`, `item`.`author-avatar`,
|
return "`item`.`author-link`, `item`.`author-name`, `item`.`author-avatar`,
|
||||||
`item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`,
|
`item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`,
|
||||||
`item`.`contact-id`, `item`.`uid`, `item`.`id`, `item`.`parent`,
|
`item`.`contact-id`, `item`.`uid`, `item`.`id`, `item`.`parent`,
|
||||||
`item`.`uri`, `item`.`thr-parent`, `item`.`parent-uri`,
|
`item`.`uri`, `item`.`thr-parent`, `item`.`parent-uri`,
|
||||||
`item`.`commented`, `item`.`created`, `item`.`edited`,
|
`item`.`commented`, `item`.`created`, `item`.`edited`,
|
||||||
`item`.`verb`, `item`.`object-type`, `item`.`postopts`, `item`.`plink`,
|
`item`.`verb`, `item`.`object-type`, `item`.`postopts`, `item`.`plink`,
|
||||||
`item`.`guid`, `item`.`wall`, `item`.`private`, `item`.`starred`,
|
`item`.`guid`, `item`.`wall`, `item`.`private`, `item`.`starred`,
|
||||||
`item`.`title`, `item`.`body`, `item`.`file`, `item`.`event-id`,
|
`item`.`title`, `item`.`body`, `item`.`file`, `item`.`event-id`,
|
||||||
`item`.`location`, `item`.`coord`, `item`.`app`,
|
`item`.`location`, `item`.`coord`, `item`.`app`,
|
||||||
`item`.`rendered-hash`, `item`.`rendered-html`,
|
`item`.`rendered-hash`, `item`.`rendered-html`,
|
||||||
`item`.`allow_cid`, `item`.`allow_gid`, `item`.`deny_cid`, `item`.`deny_gid`,
|
`item`.`allow_cid`, `item`.`allow_gid`, `item`.`deny_cid`, `item`.`deny_gid`,
|
||||||
`item`.`id` AS `item_id`, `item`.`network` AS `item_network`";
|
`item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
|
||||||
|
|
||||||
|
`author`.`thumb` AS `author-thumb`, `owner`.`thumb` AS `owner-thumb`,
|
||||||
|
|
||||||
|
`contact`.`network`, `contact`.`url`, `contact`.`name`, `contact`.`writable`,
|
||||||
|
`contact`.`self`, `contact`.`id` AS `cid`, `contact`.`alias`";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief SQL condition for items
|
* @brief SQL join for contacts that are needed for displaying items
|
||||||
|
*/
|
||||||
|
function item_joins() {
|
||||||
|
|
||||||
|
return "STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND
|
||||||
|
NOT `contact`.`blocked` AND NOT `contact`.`pending`
|
||||||
|
LEFT JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id`
|
||||||
|
LEFT JOIN `contact` AS `owner` ON `owner`.`id`=`item`.`author-id`";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief SQL condition for items that are needed for displaying items
|
||||||
*/
|
*/
|
||||||
function item_condition() {
|
function item_condition() {
|
||||||
|
|
||||||
|
@ -923,8 +881,6 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
|
||||||
|
|
||||||
function best_link_url($item,&$sparkle,$ssl_state = false) {
|
function best_link_url($item,&$sparkle,$ssl_state = false) {
|
||||||
|
|
||||||
$a = get_app();
|
|
||||||
|
|
||||||
$best_url = '';
|
$best_url = '';
|
||||||
$sparkle = false;
|
$sparkle = false;
|
||||||
|
|
||||||
|
@ -951,7 +907,6 @@ function best_link_url($item,&$sparkle,$ssl_state = false) {
|
||||||
|
|
||||||
if(! function_exists('item_photo_menu')){
|
if(! function_exists('item_photo_menu')){
|
||||||
function item_photo_menu($item){
|
function item_photo_menu($item){
|
||||||
$a = get_app();
|
|
||||||
|
|
||||||
$ssl_state = false;
|
$ssl_state = false;
|
||||||
|
|
||||||
|
|
|
@ -120,18 +120,17 @@ 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 %s, %s, `user`.`nickname`
|
$r = q("SELECT %s
|
||||||
FROM `thread` FORCE INDEX (`wall_private_received`)
|
FROM `thread` FORCE INDEX (`wall_private_received`)
|
||||||
INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND NOT `user`.`hidewall`
|
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`
|
%s AND `contact`.`self`
|
||||||
AND %s AND `contact`.`self`
|
|
||||||
WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
|
WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
|
||||||
AND NOT `thread`.`private` AND `thread`.`wall`
|
AND NOT `thread`.`private` AND `thread`.`wall`
|
||||||
ORDER BY `thread`.`received` DESC LIMIT %d, %d",
|
ORDER BY `thread`.`received` DESC LIMIT %d, %d",
|
||||||
item_fieldlist(), contact_fieldlist(), contact_condition(),
|
item_fieldlists(), item_joins(),
|
||||||
intval($start), intval($itemspage)
|
intval($start), intval($itemspage)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -141,14 +140,12 @@ function community_getitems($start, $itemspage) {
|
||||||
|
|
||||||
function community_getpublicitems($start, $itemspage) {
|
function community_getpublicitems($start, $itemspage) {
|
||||||
|
|
||||||
$r = q("SELECT %s, %s, `author-name` AS `name`, `owner-avatar` AS `photo`,
|
$r = q("SELECT %s
|
||||||
`owner-link` AS `url`, `owner-avatar` AS `thumb`
|
|
||||||
FROM `thread`
|
FROM `thread`
|
||||||
INNER JOIN `item` ON `item`.`id` = `thread`.`iid` %s
|
INNER JOIN `item` ON `item`.`id` = `thread`.`iid` %s
|
||||||
WHERE `thread`.`uid` = 0
|
WHERE `thread`.`uid` = 0
|
||||||
ORDER BY `thread`.`created` DESC LIMIT %d, %d",
|
ORDER BY `thread`.`created` DESC LIMIT %d, %d",
|
||||||
item_fieldlist(), zcontact_fieldlist(),
|
item_fieldlists(), item_joins(),
|
||||||
zcontact_join(),
|
|
||||||
intval($start), intval($itemspage)
|
intval($start), intval($itemspage)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -73,11 +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` AND %s
|
FROM `item` %s
|
||||||
WHERE %s AND `item`.`uid` = %d AND `item`.`type` = 'note'
|
WHERE %s AND `item`.`uid` = %d AND `item`.`type` = 'note'
|
||||||
AND `contact`.`self` AND `item`.`id` = `item`.`parent` AND NOT `item`.`wall`
|
AND `contact`.`self` AND `item`.`id` = `item`.`parent` AND NOT `item`.`wall`
|
||||||
$sql_extra ",
|
$sql_extra ",
|
||||||
contact_condition(), item_condition(),
|
item_joins(), item_condition(),
|
||||||
intval(local_user())
|
intval(local_user())
|
||||||
|
|
||||||
);
|
);
|
||||||
|
@ -87,13 +87,12 @@ function notes_content(&$a,$update = false) {
|
||||||
$a->set_pager_itemspage(40);
|
$a->set_pager_itemspage(40);
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = q("SELECT `item`.`id` AS `item_id` FROM `item`
|
$r = q("SELECT `item`.`id` AS `item_id` FROM `item` %s
|
||||||
LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s AND `contact`.`self`
|
|
||||||
WHERE %s AND `item`.`uid` = %d AND `item`.`type` = 'note'
|
WHERE %s AND `item`.`uid` = %d AND `item`.`type` = 'note'
|
||||||
AND `item`.`id` = `item`.`parent` AND NOT `item`.`wall`
|
AND `item`.`id` = `item`.`parent` AND NOT `item`.`wall`
|
||||||
$sql_extra
|
$sql_extra
|
||||||
ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
|
ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
|
||||||
contact_condition(), item_condition(),
|
item_joins(), item_condition(),
|
||||||
intval(local_user()),
|
intval(local_user()),
|
||||||
intval($a->pager['start']),
|
intval($a->pager['start']),
|
||||||
intval($a->pager['itemspage'])
|
intval($a->pager['itemspage'])
|
||||||
|
@ -108,13 +107,11 @@ 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 %s FROM `item`
|
$r = q("SELECT %s FROM `item` %s
|
||||||
LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s
|
|
||||||
WHERE %s AND `item`.`uid` = %d AND `item`.`parent` IN (%s)
|
WHERE %s AND `item`.`uid` = %d 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(),
|
item_fieldlists(), item_joins(), item_condition(),
|
||||||
contact_condition(), item_condition(),
|
|
||||||
intval(local_user()),
|
intval(local_user()),
|
||||||
dbesc($parents_str)
|
dbesc($parents_str)
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue