Speed improvements of queries

This commit is contained in:
Michael Vogel 2013-10-05 12:30:10 +02:00
parent 8adc1bd703
commit 2d1b261fad
3 changed files with 21 additions and 8 deletions

View file

@ -619,19 +619,32 @@
function api_status_show(&$a, $type){
$user_info = api_get_user($a);
// get last public wall message
$lastwall = q("SELECT `item`.*, `i`.`contact-id` as `reply_uid`, `i`.`nick` as `reply_author`
FROM `item`, `contact`,
(SELECT `item`.`id`, `item`.`contact-id`, `contact`.`nick` FROM `item`,`contact` WHERE `contact`.`id`=`item`.`contact-id`) as `i`
$lastwall = q("SELECT `item`.*, `i`.`contact-id` as `reply_uid`, `c`.`nick` as `reply_author`
FROM `item`, `contact`, `item` as `i`, `contact` as `c`
WHERE `item`.`contact-id` = %d
AND `i`.`id` = `item`.`parent`
AND `contact`.`id`=`item`.`contact-id` AND `contact`.`self`=1
AND `type`!='activity'
AND `contact`.`id`=`item`.`contact-id` AND `c`.`id`=`i`.`contact-id` AND `contact`.`self`=1
AND `item`.`type`!='activity'
AND `item`.`allow_cid`='' AND `item`.`allow_gid`='' AND `item`.`deny_cid`='' AND `item`.`deny_gid`=''
ORDER BY `created` DESC
ORDER BY `item`.`created` DESC
LIMIT 1",
intval($user_info['id'])
);
// $lastwall = q("SELECT `item`.*, `i`.`contact-id` as `reply_uid`, `i`.`nick` as `reply_author`
// FROM `item`, `contact`,
// (SELECT `item`.`id`, `item`.`contact-id`, `contact`.`nick` FROM `item`,`contact` WHERE `contact`.`id`=`item`.`contact-id`) as `i`
// WHERE `item`.`contact-id` = %d
// AND `i`.`id` = `item`.`parent`
// AND `contact`.`id`=`item`.`contact-id` AND `contact`.`self`=1
// AND `type`!='activity'
// AND `item`.`allow_cid`='' AND `item`.`allow_gid`='' AND `item`.`deny_cid`='' AND `item`.`deny_gid`=''
// ORDER BY `created` DESC
// LIMIT 1",
// intval($user_info['id'])
// );
if (count($lastwall)>0){
$lastwall = $lastwall[0];

View file

@ -70,7 +70,7 @@ function community_content(&$a, $update = 0) {
`contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`,
`user`.`nickname`, `user`.`hidewall`
FROM `item` FORCE INDEX (`received`) LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
FROM `item` FORCE INDEX (`received`, `wall`) LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
LEFT JOIN `user` ON `user`.`uid` = `item`.`uid`
WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''

View file

@ -277,7 +277,7 @@ function profile_content(&$a, $update = 0) {
$pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
$r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact-uid`
FROM `item` FORCE INDEX (created) LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
FROM `item` FORCE INDEX (created, uid) 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 `contact`.`blocked` = 0 AND `contact`.`pending` = 0
AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1