Optimized query for nodeinfo and admin user page

This commit is contained in:
Michael Vogel 2016-10-07 21:07:21 +00:00
parent 94f7debb52
commit b70676d231
2 changed files with 3 additions and 35 deletions

View file

@ -1306,26 +1306,8 @@ function admin_page_users(&$a){
$sql_order = "`".str_replace('.','`.`',$order)."`";
$sql_order_direction = ($order_direction==="+")?"ASC":"DESC";
/* $users = q("SELECT `user`.* , `contact`.`name` , `contact`.`url` , `contact`.`micro`, `lastitem`.`lastitem_date`, `user`.`account_expired`
FROM
(SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`
FROM `item`
WHERE `item`.`type` = 'wall'
GROUP BY `item`.`uid`) AS `lastitem`
RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`,
`contact`
WHERE
`user`.`uid` = `contact`.`uid`
AND `user`.`verified` =1
AND `contact`.`self` =1
ORDER BY $sql_order $sql_order_direction LIMIT %d, %d
",
intval($a->pager['start']),
intval($a->pager['itemspage'])
);
*/
$users = q("SELECT `user`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`account_expired`,
(SELECT `changed` FROM `item` WHERE `wall` AND `uid` = `user`.`uid` ORDER BY `changed` DESC LIMIT 1) AS `lastitem_date`
(SELECT MAX(`changed`) FROM `item` FORCE INDEX (`uid_wall_changed`) WHERE `wall` AND `uid` = `user`.`uid`) AS `lastitem_date`
FROM `user`
INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
WHERE `user`.`verified`

View file

@ -184,23 +184,9 @@ function nodeinfo_cron() {
}
}
logger("cron_start");
/*
$users = q("SELECT profile.*, `user`.`login_date`, `lastitem`.`lastitem_date`
FROM (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`
FROM `item`
WHERE `item`.`type` = 'wall'
GROUP BY `item`.`uid`) AS `lastitem`
RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`, `contact`, `profile`
WHERE
`user`.`uid` = `contact`.`uid` AND `profile`.`uid` = `user`.`uid`
AND `profile`.`is-default` AND (`profile`.`publish` OR `profile`.`net-publish`)
AND `user`.`verified` AND `contact`.`self`
AND NOT `user`.`blocked`
AND NOT `user`.`account_removed`
AND NOT `user`.`account_expired`");
*/
$users = q("SELECT `user`.`uid`, `user`.`login_date`,
(SELECT `changed` FROM `item` WHERE `wall` AND `uid` = `user`.`uid` ORDER BY `changed` DESC LIMIT 1) AS `lastitem_date`
(SELECT MAX(`changed`) FROM `item` FORCE INDEX (`uid_wall_changed`) WHERE `wall` AND `uid` = `user`.`uid`) AS `lastitem_date`
FROM `user`
INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid` AND `profile`.`is-default`
WHERE (`profile`.`publish` OR `profile`.`net-publish`) AND `user`.`verified`