From aec69ff19c3e375b4b0e13a0597193f074a09180 Mon Sep 17 00:00:00 2001 From: flashwave Date: Sat, 2 Mar 2019 20:29:41 +0100 Subject: [PATCH] Moved stats into a single db_query call. --- public/index.php | 50 ++++++++++++++++++------------------- templates/home/landing.twig | 12 ++++----- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/public/index.php b/public/index.php index f1ca2748..dc00e4e4 100644 --- a/public/index.php +++ b/public/index.php @@ -12,41 +12,39 @@ if (config_get_default(false, 'Site', 'embed_linked_data')) { $news = news_posts_get(0, 5, null, true); -$stats = [ - 'users' => db_query(' - SELECT - ( - SELECT COUNT(`user_id`) - FROM `msz_users` - WHERE `user_deleted` IS NULL - ) as `all`, - ( - SELECT COUNT(`user_id`) - FROM `msz_users` - WHERE `user_active` >= DATE_SUB(NOW(), INTERVAL 5 MINUTE) - ) as `online`, - ( - SELECT COUNT(`user_id`) - FROM `msz_users` - WHERE `user_active` >= DATE_SUB(NOW(), INTERVAL 24 HOUR) - ) as `active` - ')->fetch(PDO::FETCH_ASSOC), - 'comments' => (int)db_query(' +$stats = db_fetch(db_query(' + SELECT + ( + SELECT COUNT(`user_id`) + FROM `msz_users` + WHERE `user_deleted` IS NULL + ) AS `count_users_all`, + ( + SELECT COUNT(`user_id`) + FROM `msz_users` + WHERE `user_active` >= DATE_SUB(NOW(), INTERVAL 5 MINUTE) + ) AS `count_users_online`, + ( + SELECT COUNT(`user_id`) + FROM `msz_users` + WHERE `user_active` >= DATE_SUB(NOW(), INTERVAL 24 HOUR) + ) AS `count_users_active`, + ( SELECT COUNT(`comment_id`) FROM `msz_comments_posts` WHERE `comment_deleted` IS NULL - ')->fetchColumn(), - 'forum_topics' => (int)db_query(' + ) AS `count_comments`, + ( SELECT COUNT(`topic_id`) FROM `msz_forum_topics` WHERE `topic_deleted` IS NULL - ')->fetchColumn(), - 'forum_posts' => (int)db_query(' + ) AS `count_forum_topics`, + ( SELECT COUNT(`post_id`) FROM `msz_forum_posts` WHERE `post_deleted` IS NULL - ')->fetchColumn(), -]; + ) AS `count_forum_posts` +')); $changelog = db_query(' SELECT diff --git a/templates/home/landing.twig b/templates/home/landing.twig index 25d29f1c..bf1c9faa 100644 --- a/templates/home/landing.twig +++ b/templates/home/landing.twig @@ -18,7 +18,7 @@ Users
- {{ statistics.users.all|number_format }} + {{ statistics.count_users_all|number_format }}
@@ -27,7 +27,7 @@ Comments
- {{ statistics.comments|number_format }} + {{ statistics.count_comments|number_format }}
@@ -36,7 +36,7 @@ Online
- {{ statistics.users.online|number_format }} + {{ statistics.count_users_online|number_format }}
@@ -45,7 +45,7 @@ Active (24 hr)
- {{ statistics.users.active|number_format }} + {{ statistics.count_users_active|number_format }}
@@ -54,7 +54,7 @@ Topics
- {{ statistics.forum_topics|number_format }} + {{ statistics.count_forum_topics|number_format }}
@@ -63,7 +63,7 @@ Posts
- {{ statistics.forum_posts|number_format }} + {{ statistics.count_forum_posts|number_format }}