Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
feat(Debug): Add extend debug output
Browse files Browse the repository at this point in the history
1. Show SQL execute query and Redis keys hit log for SYSOP
2. Fix CSS style for tag li
3. Add two site config key `authority.see_extend_debug_log` and
   `base.enable_extend_debug`
  • Loading branch information
Rhilip committed May 30, 2019
1 parent fbc98ad commit 9d4f0cb
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
4 changes: 2 additions & 2 deletions apps/public/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ body{background-color:#f6f6f6}
/* '/torrent/details' */
.torrent-details-block{}
.torrent-action-item{padding:3px}
#torrent_extend_info_panel_group > hr{margin:0}
#torrent_extend_info_panel_group hr{margin:10px 0}

/* '/torrent/structure' */
#torrent_structure ul{}
#torrent_structure ul,li{list-style-type:none;color:#000}
#torrent_structure ul,#torrent_structure li{list-style-type:none;color:#000}
#torrent_structure li div.string{padding:3px}
#torrent_structure li div.integer{padding:3px}
#torrent_structure li div.dictionary{padding:3px}
Expand Down
22 changes: 22 additions & 0 deletions apps/public/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,27 @@ jQuery(document).ready(function() {
$('#torrent_structure div.dictionary,div.list').click(function () {
$(this).next('ul').toggle();
});
};

// Show Extend debug info of Database sql execute and Redis key hit
if (typeof _extend_debug_info !== 'undefined' && _extend_debug_info) {
$('#extend_debug_info').modalTrigger({
size: 'lg',
custom: function () {
let ret = '';
let parsed_sql_data = JSON.parse(_sql_data || '[]');
let parsed_redis_data = JSON.parse(_redis_data || '{}');
ret += '<b>SQL query list:</b><ul>';
$.each(parsed_sql_data,function (i,v) {
ret += `<li><code>${v}</code></li>`;
});
ret += '</ul>';
ret += '<b>Redis key hit:</b><ul>';
$.each(parsed_redis_data,function (k, v) {
ret += '<li><code>' + k + "</code> : " + v + '</li>';
});
ret += '</ul>';
return ret;
}});
}
});
17 changes: 16 additions & 1 deletion apps/views/layout/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/

$css_tag = env('APP_DEBUG') ? time() : app()->config->get('base.site_css_update_date');
$extend_debug_info = app()->config->get('base.enable_extend_debug') &&
app()->user->getClass(true) > app()->config->get('authority.see_extend_debug_log');
?>
<!DOCTYPE html>
<html lang="en">
Expand Down Expand Up @@ -140,7 +142,20 @@
<p class="copyright">
&copy; <a href="/" target="_self"><?= app()->config->get('base.site_name') ?></a> 2019-2020 Powered by <a href="https://github.com/Rhilip/RidPT">RidPT</a>
</p>
<p class="create-debug-info">[ Page created in <b><?= number_format(microtime(true) - app()->request->start_at, 6) ?></b> sec with <b><?= $this->e(memory_get_usage(),'format_bytes') ?></b> ram used, <b><?= count(app()->pdo->getExecuteData()) ?></b> db queries, <b><?= array_sum(app()->redis->getCalledData())?></b> calls of Redis ]</p>
<p class="debug-info">
[ Page created in <b><?= number_format(microtime(true) - app()->request->start_at, 6) ?></b> sec
with <b><?= $this->e(memory_get_usage(),'format_bytes') ?></b> ram used,
<b><?= count(app()->pdo->getExecuteData()) ?></b> db queries,
<b><?= array_sum(app()->redis->getCalledData())?></b> calls of Redis ]
<?php if ($extend_debug_info): ?>
<a href="javascript:" id="extend_debug_info"><span class="label label-warning label-outline">Debug info</span></a>
<script>
const _extend_debug_info = true;
const _sql_data = '<?= json_encode(app()->pdo->getExecuteData(), JSON_HEX_APOS) ?>';
const _redis_data = '<?= json_encode(app()->redis->getCalledData(), JSON_HEX_APOS) ?>';
</script>
<?php endif; ?>
</p>
</div>
</div>
</footer>
Expand Down
10 changes: 6 additions & 4 deletions migration/ridpt.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Mar 19, 2019 at 03:13 PM
-- Server version: 8.0.14
-- PHP Version: 7.3.1
-- Generation Time: May 30, 2019 at 09:53 PM
-- Server version: 8.0.16
-- PHP Version: 7.3.5

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
Expand Down Expand Up @@ -350,8 +350,10 @@ INSERT INTO `site_config` (`name`, `value`) VALUES
('authority.route_admin_service', '90'),
('authority.see_anonymous_uploader', '40'),
('authority.see_banned_torrent', '40'),
('authority.see_extend_debug_log', '90'),
('authority.see_pending_torrent', '40'),
('authority.upload_anonymous', '5'),
('base.enable_extend_debug', '1'),
('base.enable_register_system', '1'),
('base.enable_tracker_system', '1'),
('base.max_per_user_session', '10'),
Expand Down Expand Up @@ -381,7 +383,7 @@ INSERT INTO `site_config` (`name`, `value`) VALUES
('buff.random_percent_free', '2'),
('register.by_green', '0'),
('register.by_invite', '1'),
('register.by_open', '0'),
('register.by_open', '1'),
('register.email_black_list', '@test.com'),
('register.email_white_list', '@gmail.com'),
('register.enabled_email_black_list', '1'),
Expand Down

0 comments on commit 9d4f0cb

Please sign in to comment.