Moved stats into a single db_query call.

This commit is contained in:
flash 2019-03-02 20:29:41 +01:00
parent 35d7150965
commit aec69ff19c
2 changed files with 30 additions and 32 deletions

View file

@ -12,41 +12,39 @@ if (config_get_default(false, 'Site', 'embed_linked_data')) {
$news = news_posts_get(0, 5, null, true); $news = news_posts_get(0, 5, null, true);
$stats = [ $stats = db_fetch(db_query('
'users' => db_query(' SELECT
SELECT (
( SELECT COUNT(`user_id`)
SELECT COUNT(`user_id`) FROM `msz_users`
FROM `msz_users` WHERE `user_deleted` IS NULL
WHERE `user_deleted` IS NULL ) AS `count_users_all`,
) as `all`, (
( SELECT COUNT(`user_id`)
SELECT COUNT(`user_id`) FROM `msz_users`
FROM `msz_users` WHERE `user_active` >= DATE_SUB(NOW(), INTERVAL 5 MINUTE)
WHERE `user_active` >= DATE_SUB(NOW(), INTERVAL 5 MINUTE) ) AS `count_users_online`,
) as `online`, (
( SELECT COUNT(`user_id`)
SELECT COUNT(`user_id`) FROM `msz_users`
FROM `msz_users` WHERE `user_active` >= DATE_SUB(NOW(), INTERVAL 24 HOUR)
WHERE `user_active` >= DATE_SUB(NOW(), INTERVAL 24 HOUR) ) AS `count_users_active`,
) as `active` (
')->fetch(PDO::FETCH_ASSOC),
'comments' => (int)db_query('
SELECT COUNT(`comment_id`) SELECT COUNT(`comment_id`)
FROM `msz_comments_posts` FROM `msz_comments_posts`
WHERE `comment_deleted` IS NULL WHERE `comment_deleted` IS NULL
')->fetchColumn(), ) AS `count_comments`,
'forum_topics' => (int)db_query(' (
SELECT COUNT(`topic_id`) SELECT COUNT(`topic_id`)
FROM `msz_forum_topics` FROM `msz_forum_topics`
WHERE `topic_deleted` IS NULL WHERE `topic_deleted` IS NULL
')->fetchColumn(), ) AS `count_forum_topics`,
'forum_posts' => (int)db_query(' (
SELECT COUNT(`post_id`) SELECT COUNT(`post_id`)
FROM `msz_forum_posts` FROM `msz_forum_posts`
WHERE `post_deleted` IS NULL WHERE `post_deleted` IS NULL
')->fetchColumn(), ) AS `count_forum_posts`
]; '));
$changelog = db_query(' $changelog = db_query('
SELECT SELECT

View file

@ -18,7 +18,7 @@
<i class="fas fa-users fa-fw"></i> Users <i class="fas fa-users fa-fw"></i> Users
</div> </div>
<div class="index__statistic__value"> <div class="index__statistic__value">
{{ statistics.users.all|number_format }} {{ statistics.count_users_all|number_format }}
</div> </div>
</div> </div>
@ -27,7 +27,7 @@
<i class="fas fa-comment-dots fa-fw"></i> Comments <i class="fas fa-comment-dots fa-fw"></i> Comments
</div> </div>
<div class="index__statistic__value"> <div class="index__statistic__value">
{{ statistics.comments|number_format }} {{ statistics.count_comments|number_format }}
</div> </div>
</div> </div>
@ -36,7 +36,7 @@
<i class="fas fa-user-check fa-fw"></i> Online <i class="fas fa-user-check fa-fw"></i> Online
</div> </div>
<div class="index__statistic__value"> <div class="index__statistic__value">
{{ statistics.users.online|number_format }} {{ statistics.count_users_online|number_format }}
</div> </div>
</div> </div>
@ -45,7 +45,7 @@
<i class="fas fa-user-clock fa-fw"></i> Active (24 hr) <i class="fas fa-user-clock fa-fw"></i> Active (24 hr)
</div> </div>
<div class="index__statistic__value"> <div class="index__statistic__value">
{{ statistics.users.active|number_format }} {{ statistics.count_users_active|number_format }}
</div> </div>
</div> </div>
@ -54,7 +54,7 @@
<i class="fas fa-list fa-fw"></i> Topics <i class="fas fa-list fa-fw"></i> Topics
</div> </div>
<div class="index__statistic__value"> <div class="index__statistic__value">
{{ statistics.forum_topics|number_format }} {{ statistics.count_forum_topics|number_format }}
</div> </div>
</div> </div>
@ -63,7 +63,7 @@
<i class="fas fa-comments fa-fw"></i> Posts <i class="fas fa-comments fa-fw"></i> Posts
</div> </div>
<div class="index__statistic__value"> <div class="index__statistic__value">
{{ statistics.forum_posts|number_format }} {{ statistics.count_forum_posts|number_format }}
</div> </div>
</div> </div>