Better indexing and added statistics overview to manage.
This commit is contained in:
parent
fd6a4f4629
commit
9d5376926f
6 changed files with 361 additions and 3 deletions
|
@ -35,3 +35,5 @@
|
|||
@import "user-item";
|
||||
@import "user";
|
||||
@import "users";
|
||||
@import "statistic";
|
||||
@import "statistics";
|
||||
|
|
16
assets/less/manage/statistic.less
Normal file
16
assets/less/manage/statistic.less
Normal file
|
@ -0,0 +1,16 @@
|
|||
.manage__statistic {
|
||||
border: 1px solid var(--accent-colour);
|
||||
border-radius: 2px;
|
||||
padding: 2px 5px;
|
||||
|
||||
&__name {
|
||||
font-size: 1.1em;
|
||||
line-height: 1.5em;
|
||||
}
|
||||
|
||||
&__value {
|
||||
text-align: right;
|
||||
font-size: 1.5em;
|
||||
line-height: 2em;
|
||||
}
|
||||
}
|
14
assets/less/manage/statistics.less
Normal file
14
assets/less/manage/statistics.less
Normal file
|
@ -0,0 +1,14 @@
|
|||
.manage__statistics {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr 1fr;
|
||||
padding: 5px;
|
||||
grid-gap: 5px;
|
||||
|
||||
@media (max-width: 900px) {
|
||||
grid-template-columns: 1fr 1fr;
|
||||
}
|
||||
|
||||
@media (max-width: 500px) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
100
database/2019_04_12_224041_add_more_indices.php
Normal file
100
database/2019_04_12_224041_add_more_indices.php
Normal file
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
namespace Misuzu\DatabaseMigrations\AddMoreIndices;
|
||||
|
||||
use PDO;
|
||||
|
||||
function migrate_up(PDO $conn): void
|
||||
{
|
||||
$conn->exec("
|
||||
ALTER TABLE `msz_forum_posts`
|
||||
ADD INDEX `posts_parse_index` (`post_parse`),
|
||||
ADD INDEX `posts_edited_index` (`post_edited`),
|
||||
ADD INDEX `posts_display_signature_index` (`post_display_signature`),
|
||||
ADD INDEX `posts_ip_index` (`post_ip`),
|
||||
ADD FULLTEXT INDEX `posts_fulltext` (`post_text`);
|
||||
");
|
||||
|
||||
$conn->exec("
|
||||
ALTER TABLE `msz_comments_categories`
|
||||
ADD INDEX `comments_categories_locked_index` (`category_locked`);
|
||||
");
|
||||
|
||||
$conn->exec("
|
||||
ALTER TABLE `msz_forum_topics`
|
||||
DROP INDEX `topics_indices`,
|
||||
ADD FULLTEXT INDEX `topics_fulltext` (`topic_title`),
|
||||
ADD INDEX `topics_type_index` (`topic_type`),
|
||||
ADD INDEX `topics_created_index` (`topic_created`),
|
||||
ADD INDEX `topics_bumped_index` (`topic_bumped`),
|
||||
ADD INDEX `topics_deleted_index` (`topic_deleted`),
|
||||
ADD INDEX `topics_locked_index` (`topic_locked`);
|
||||
");
|
||||
|
||||
$conn->exec("
|
||||
ALTER TABLE `msz_news_posts`
|
||||
DROP INDEX `news_posts_indices`,
|
||||
ADD INDEX `news_posts_featured_index` (`post_is_featured`),
|
||||
ADD INDEX `news_posts_scheduled_index` (`post_scheduled`),
|
||||
ADD INDEX `news_posts_created_index` (`post_created`),
|
||||
ADD INDEX `news_posts_updated_index` (`post_updated`),
|
||||
ADD INDEX `news_posts_deleted_index` (`post_deleted`),
|
||||
ADD FULLTEXT INDEX `news_posts_fulltext` (`post_title`, `post_text`);
|
||||
");
|
||||
|
||||
$conn->exec("
|
||||
ALTER TABLE `msz_user_warnings`
|
||||
DROP INDEX `user_warnings_indices`,
|
||||
ADD INDEX `user_warnings_created_index` (`warning_created`),
|
||||
ADD INDEX `user_warnings_duration_index` (`warning_duration`),
|
||||
ADD INDEX `user_warnings_type_index` (`warning_type`),
|
||||
ADD INDEX `user_warnings_user_ip_index` (`user_ip`);
|
||||
");
|
||||
}
|
||||
|
||||
function migrate_down(PDO $conn): void
|
||||
{
|
||||
$conn->exec("
|
||||
ALTER TABLE `msz_user_warnings`
|
||||
DROP INDEX `user_warnings_user_ip_index`,
|
||||
DROP INDEX `user_warnings_type_index`,
|
||||
DROP INDEX `user_warnings_duration_index`,
|
||||
DROP INDEX `user_warnings_created_index`,
|
||||
ADD INDEX `user_warnings_indices` (`warning_created`, `warning_type`, `warning_duration`, `user_ip`);
|
||||
");
|
||||
|
||||
$conn->exec("
|
||||
ALTER TABLE `msz_news_posts`
|
||||
DROP INDEX `news_posts_fulltext`,
|
||||
DROP INDEX `news_posts_deleted_index`,
|
||||
DROP INDEX `news_posts_created_index`,
|
||||
DROP INDEX `news_posts_updated_index`,
|
||||
DROP INDEX `news_posts_scheduled_index`,
|
||||
DROP INDEX `news_posts_featured_index`,
|
||||
ADD INDEX `news_posts_indices` (`post_is_featured`, `post_scheduled`, `post_created`);
|
||||
");
|
||||
|
||||
$conn->exec("
|
||||
ALTER TABLE `msz_forum_topics`
|
||||
DROP INDEX `topics_fulltext`,
|
||||
DROP INDEX `topics_locked_index`,
|
||||
DROP INDEX `topics_deleted_index`,
|
||||
DROP INDEX `topics_created_index`,
|
||||
DROP INDEX `topics_bumped_index`,
|
||||
DROP INDEX `topics_type_index`,
|
||||
ADD INDEX `topics_indices` (`topic_type`, `topic_bumped`);
|
||||
");
|
||||
|
||||
$conn->exec("
|
||||
ALTER TABLE `msz_comments_categories`
|
||||
DROP INDEX `comments_categories_locked_index`;
|
||||
");
|
||||
|
||||
$conn->exec("
|
||||
ALTER TABLE `msz_forum_posts`
|
||||
DROP INDEX `posts_fulltext`,
|
||||
DROP INDEX `posts_ip_index`,
|
||||
DROP INDEX `posts_display_signature_index`,
|
||||
DROP INDEX `posts_edited_index`,
|
||||
DROP INDEX `posts_parse_index`,;
|
||||
");
|
||||
}
|
|
@ -6,7 +6,183 @@ $generalPerms = perms_get_user(MSZ_PERMS_GENERAL, user_session_current('user_id'
|
|||
switch ($_GET['v'] ?? null) {
|
||||
default:
|
||||
case 'overview':
|
||||
echo tpl_render('manage.general.overview');
|
||||
$statistics = db_fetch(db_query('
|
||||
SELECT
|
||||
(
|
||||
SELECT COUNT(`user_id`)
|
||||
FROM `msz_users`
|
||||
) AS `stat_users_total`,
|
||||
(
|
||||
SELECT COUNT(`user_id`)
|
||||
FROM `msz_users`
|
||||
WHERE `user_deleted` IS NOT NULL
|
||||
) AS `stat_users_deleted`,
|
||||
(
|
||||
SELECT COUNT(`user_id`)
|
||||
FROM `msz_users`
|
||||
WHERE `user_active` IS NOT NULL
|
||||
AND `user_deleted` IS NULL
|
||||
) AS `stat_users_active`,
|
||||
(
|
||||
SELECT COUNT(`log_id`)
|
||||
FROM `msz_audit_log`
|
||||
) AS `stat_audit_logs`,
|
||||
(
|
||||
SELECT COUNT(`change_id`)
|
||||
FROM `msz_changelog_changes`
|
||||
) AS `stat_changelog_entries`,
|
||||
(
|
||||
SELECT COUNT(`category_id`)
|
||||
FROM `msz_comments_categories`
|
||||
) AS `stat_comment_categories_total`,
|
||||
(
|
||||
SELECT COUNT(`category_id`)
|
||||
FROM `msz_comments_categories`
|
||||
WHERE `category_locked` IS NOT NULL
|
||||
) AS `stat_comment_categories_locked`,
|
||||
(
|
||||
SELECT COUNT(`comment_id`)
|
||||
FROM `msz_comments_posts`
|
||||
) AS `stat_comment_posts_total`,
|
||||
(
|
||||
SELECT COUNT(`comment_id`)
|
||||
FROM `msz_comments_posts`
|
||||
WHERE `comment_deleted` IS NOT NULL
|
||||
) AS `stat_comment_posts_deleted`,
|
||||
(
|
||||
SELECT COUNT(`comment_id`)
|
||||
FROM `msz_comments_posts`
|
||||
WHERE `comment_reply_to` IS NOT NULL
|
||||
) AS `stat_comment_posts_replies`,
|
||||
(
|
||||
SELECT COUNT(`comment_id`)
|
||||
FROM `msz_comments_posts`
|
||||
WHERE `comment_pinned` IS NOT NULL
|
||||
) AS `stat_comment_posts_pinned`,
|
||||
(
|
||||
SELECT COUNT(`comment_id`)
|
||||
FROM `msz_comments_posts`
|
||||
WHERE `comment_edited` IS NOT NULL
|
||||
) AS `stat_comment_posts_edited`,
|
||||
(
|
||||
SELECT COUNT(`user_id`)
|
||||
FROM `msz_comments_votes`
|
||||
WHERE `comment_vote` > 0
|
||||
) AS `stat_comment_likes`,
|
||||
(
|
||||
SELECT COUNT(`user_id`)
|
||||
FROM `msz_comments_votes`
|
||||
WHERE `comment_vote` < 0
|
||||
) AS `stat_comment_dislikes`,
|
||||
(
|
||||
SELECT COUNT(`post_id`)
|
||||
FROM `msz_forum_posts`
|
||||
) AS `stat_forum_posts_total`,
|
||||
(
|
||||
SELECT COUNT(`post_id`)
|
||||
FROM `msz_forum_posts`
|
||||
WHERE `post_deleted` IS NOT NULL
|
||||
) AS `stat_forum_posts_deleted`,
|
||||
(
|
||||
SELECT COUNT(`post_id`)
|
||||
FROM `msz_forum_posts`
|
||||
WHERE `post_edited` IS NOT NULL
|
||||
) AS `stat_forum_posts_edited`,
|
||||
(
|
||||
SELECT COUNT(`post_id`)
|
||||
FROM `msz_forum_posts`
|
||||
WHERE `post_parse` = 0
|
||||
) AS `stat_forum_posts_plain`,
|
||||
(
|
||||
SELECT COUNT(`post_id`)
|
||||
FROM `msz_forum_posts`
|
||||
WHERE `post_parse` = 1
|
||||
) AS `stat_forum_posts_bbcode`,
|
||||
(
|
||||
SELECT COUNT(`post_id`)
|
||||
FROM `msz_forum_posts`
|
||||
WHERE `post_parse` = 2
|
||||
) AS `stat_forum_posts_markdown`,
|
||||
(
|
||||
SELECT COUNT(`post_id`)
|
||||
FROM `msz_forum_posts`
|
||||
WHERE `post_display_signature` != 0
|
||||
) AS `stat_forum_posts_signature`,
|
||||
(
|
||||
SELECT COUNT(`topic_id`)
|
||||
FROM `msz_forum_topics`
|
||||
) AS `stat_forum_topics_total`,
|
||||
(
|
||||
SELECT COUNT(`topic_id`)
|
||||
FROM `msz_forum_topics`
|
||||
WHERE `topic_type` = 0
|
||||
) AS `stat_forum_topics_normal`,
|
||||
(
|
||||
SELECT COUNT(`topic_id`)
|
||||
FROM `msz_forum_topics`
|
||||
WHERE `topic_type` = 1
|
||||
) AS `stat_forum_topics_pinned`,
|
||||
(
|
||||
SELECT COUNT(`topic_id`)
|
||||
FROM `msz_forum_topics`
|
||||
WHERE `topic_type` = 2
|
||||
) AS `stat_forum_topics_announce`,
|
||||
(
|
||||
SELECT COUNT(`topic_id`)
|
||||
FROM `msz_forum_topics`
|
||||
WHERE `topic_type` = 3
|
||||
) AS `stat_forum_topics_global_announce`,
|
||||
(
|
||||
SELECT COUNT(`topic_id`)
|
||||
FROM `msz_forum_topics`
|
||||
WHERE `topic_deleted` IS NOT NULL
|
||||
) AS `stat_forum_topics_deleted`,
|
||||
(
|
||||
SELECT COUNT(`topic_id`)
|
||||
FROM `msz_forum_topics`
|
||||
WHERE `topic_locked` IS NOT NULL
|
||||
) AS `stat_forum_topics_locked`,
|
||||
(
|
||||
SELECT COUNT(*)
|
||||
FROM `msz_ip_blacklist`
|
||||
) AS `stat_blacklist`,
|
||||
(
|
||||
SELECT COUNT(`attempt_id`)
|
||||
FROM `msz_login_attempts`
|
||||
) AS `stat_login_attempts_total`,
|
||||
(
|
||||
SELECT COUNT(`attempt_id`)
|
||||
FROM `msz_login_attempts`
|
||||
WHERE `attempt_success` = 0
|
||||
) AS `stat_login_attempts_failed`,
|
||||
(
|
||||
SELECT COUNT(`session_id`)
|
||||
FROM `msz_sessions`
|
||||
) AS `stat_user_sessions`,
|
||||
(
|
||||
SELECT COUNT(`user_id`)
|
||||
FROM `msz_users_password_resets`
|
||||
) AS `stat_user_password_resets`,
|
||||
(
|
||||
SELECT COUNT(`user_id`)
|
||||
FROM `msz_user_relations`
|
||||
) AS `stat_user_relations`,
|
||||
(
|
||||
SELECT COUNT(`warning_id`)
|
||||
FROM `msz_user_warnings`
|
||||
WHERE `warning_type` != 0
|
||||
) AS `stat_user_warnings`
|
||||
'));
|
||||
|
||||
if (!empty($_GET['poll'])) {
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo json_encode($statistics);
|
||||
return;
|
||||
}
|
||||
|
||||
echo tpl_render('manage.general.overview', [
|
||||
'statistics' => $statistics,
|
||||
]);
|
||||
break;
|
||||
|
||||
case 'logs':
|
||||
|
|
|
@ -1,13 +1,63 @@
|
|||
{% extends 'manage/general/master.twig' %}
|
||||
{% from 'macros.twig' import container_title %}
|
||||
|
||||
{% set stat_names = {
|
||||
'stat_users_total': 'Total Users',
|
||||
'stat_users_deleted': 'Deleted Users',
|
||||
'stat_users_active': 'Active Users',
|
||||
'stat_audit_logs': 'Logged Actions',
|
||||
'stat_changelog_entries': 'Changelogs',
|
||||
'stat_comment_categories_total': 'Comment Sections',
|
||||
'stat_comment_categories_locked': 'Locked Comment Sections',
|
||||
'stat_comment_posts_total': 'Total Comments',
|
||||
'stat_comment_posts_deleted': 'Deleted Comments',
|
||||
'stat_comment_posts_replies': 'Comment Replies',
|
||||
'stat_comment_posts_pinned': 'Pinned Comments',
|
||||
'stat_comment_posts_edited': 'Edited Comments',
|
||||
'stat_comment_likes': 'Comments Like Votes',
|
||||
'stat_comment_dislikes': 'Comments Dislike Votes',
|
||||
'stat_forum_posts_total': 'Total Forum Posts',
|
||||
'stat_forum_posts_deleted': 'Deleted Forum Posts',
|
||||
'stat_forum_posts_edited': 'Edited Forum Posts',
|
||||
'stat_forum_posts_plain': 'Forum Posts using Plain Text',
|
||||
'stat_forum_posts_bbcode': 'Forum Posts using BBCode',
|
||||
'stat_forum_posts_markdown': 'Forum Posts using Markdown',
|
||||
'stat_forum_posts_signature': 'Forum Posts with Visible Signature',
|
||||
'stat_forum_topics_total': 'Total Forum Topics',
|
||||
'stat_forum_topics_normal': 'Regular Forum Topics',
|
||||
'stat_forum_topics_pinned': 'Pinned Forum Topics',
|
||||
'stat_forum_topics_announce': 'Announcement Forum Topics',
|
||||
'stat_forum_topics_global_announce': 'Global Announcement Forum Topics',
|
||||
'stat_forum_topics_deleted': 'Deleted Forum Topics',
|
||||
'stat_forum_topics_locked': 'Locked Forum Topics',
|
||||
'stat_blacklist': 'Blacklisted IP addresses',
|
||||
'stat_login_attempts_total': 'Total Login Attempts',
|
||||
'stat_login_attempts_failed': 'Failed Login Attempts',
|
||||
'stat_user_sessions': 'Active User Sessions',
|
||||
'stat_user_password_resets': 'Pending Password Resets',
|
||||
'stat_user_relations': 'User Relations',
|
||||
'stat_user_warnings': 'User Warnings',
|
||||
} %}
|
||||
|
||||
{% block manage_content %}
|
||||
<div class="container">
|
||||
<div class="container container--lazy">
|
||||
{{ container_title('Overview') }}
|
||||
|
||||
<div class="container__content">
|
||||
<p>Welcome to Manage, here you can manage things.</p>
|
||||
<p>Please teach me how to give a shit about management panel. -flashwave</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container container--lazy">
|
||||
{{ container_title('Statistics') }}
|
||||
|
||||
<div class="manage__statistics">
|
||||
{% for name, value in statistics %}
|
||||
<div class="manage__statistic" id="{{ name }}">
|
||||
<div class="manage__statistic__name">{{ stat_names[name]|default(name) }}</div>
|
||||
<div class="manage__statistic__value">{{ value|number_format }}</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in a new issue