From b70676d2314bb9310d3f39857d982309f36bbc09 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 7 Oct 2016 21:07:21 +0000 Subject: [PATCH] Optimized query for nodeinfo and admin user page --- mod/admin.php | 20 +------------------- mod/nodeinfo.php | 18 ++---------------- 2 files changed, 3 insertions(+), 35 deletions(-) diff --git a/mod/admin.php b/mod/admin.php index b11faa39ac..c9ff23e2d8 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -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` diff --git a/mod/nodeinfo.php b/mod/nodeinfo.php index fae2b10522..585659e5cb 100644 --- a/mod/nodeinfo.php +++ b/mod/nodeinfo.php @@ -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`