Improved queries for the nodeinfo functionality and the admin page

This commit is contained in:
Michael Vogel 2016-10-04 03:51:13 +00:00
parent 32f49b4de2
commit 66bec9475d
2 changed files with 27 additions and 11 deletions

View File

@ -1281,7 +1281,7 @@ function admin_page_users(&$a){
'user.email', 'user.email',
'user.register_date', 'user.register_date',
'user.login_date', 'user.login_date',
'lastitem.lastitem_date', 'lastitem_date',
'user.page-flags' 'user.page-flags'
); );
@ -1299,13 +1299,12 @@ function admin_page_users(&$a){
} }
if (x($_GET,'d')){ if (x($_GET,'d')){
$new_direction = $_GET['d']; $new_direction = $_GET['d'];
} }
} }
$sql_order = "`".str_replace('.','`.`',$order)."`"; $sql_order = "`".str_replace('.','`.`',$order)."`";
$sql_order_direction = ($order_direction==="+")?"ASC":"DESC"; $sql_order_direction = ($order_direction==="+")?"ASC":"DESC";
$users = q("SELECT `user`.* , `contact`.`name` , `contact`.`url` , `contact`.`micro`, `lastitem`.`lastitem_date`, `user`.`account_expired` /* $users = q("SELECT `user`.* , `contact`.`name` , `contact`.`url` , `contact`.`micro`, `lastitem`.`lastitem_date`, `user`.`account_expired`
FROM FROM
(SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid` (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`
FROM `item` FROM `item`
@ -1322,6 +1321,16 @@ function admin_page_users(&$a){
intval($a->pager['start']), intval($a->pager['start']),
intval($a->pager['itemspage']) 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`
FROM `user`
INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
WHERE `user`.`verified`
ORDER BY $sql_order $sql_order_direction LIMIT %d, %d",
intval($a->pager['start']),
intval($a->pager['itemspage'])
);
//echo "<pre>$users"; killme(); //echo "<pre>$users"; killme();

View File

@ -184,7 +184,7 @@ function nodeinfo_cron() {
} }
} }
logger("cron_start"); logger("cron_start");
/*
$users = q("SELECT profile.*, `user`.`login_date`, `lastitem`.`lastitem_date` $users = q("SELECT profile.*, `user`.`login_date`, `lastitem`.`lastitem_date`
FROM (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid` FROM (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`
FROM `item` FROM `item`
@ -198,7 +198,14 @@ function nodeinfo_cron() {
AND NOT `user`.`blocked` AND NOT `user`.`blocked`
AND NOT `user`.`account_removed` AND NOT `user`.`account_removed`
AND NOT `user`.`account_expired`"); 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`
FROM `user`
INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid` AND `profile`.`is-default`
WHERE (`profile`.`publish` OR `profile`.`net-publish`) AND `user`.`verified`
AND NOT `user`.`blocked` AND NOT `user`.`account_removed`
AND NOT `user`.`account_expired`");
if (is_array($users)) { if (is_array($users)) {
$total_users = count($users); $total_users = count($users);
$active_users_halfyear = 0; $active_users_halfyear = 0;