From f3a29eac31ee0293ca3c0d6a8f3831620bbcd837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Wed, 2 Dec 2020 09:06:10 +0100 Subject: [PATCH] do not run expensive selftest on every /admin site visit --- www/data/javascript/admin.js | 43 ++++++++++++++++++++++++------ www/internals/modules/selftest.php | 3 ++- www/pages/admin.php | 12 +++++---- 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/www/data/javascript/admin.js b/www/data/javascript/admin.js index 27eb639..4b6ebf7 100644 --- a/www/data/javascript/admin.js +++ b/www/data/javascript/admin.js @@ -87,20 +87,24 @@ function showSelfTestOutput(id1, id2) } -function refreshConsistencyDisplaySequential(skip) +function refreshConsistencyDisplaySequential(skip, filter) { + let all = (filter === '') ? $('.selftest_parent .consistence_ajax_handler') : $('.selftest_sequential .consistence_ajax_handler[data-root="'+filter+'"]'); + let i = 0; - for (let apibutton of $('.selftest_sequential .consistence_ajax_handler').toArray()) + for (let apibutton of all.toArray()) { if (i++ !== skip) continue; - refreshSingle(apibutton, () => setTimeout(() => refreshConsistencyDisplaySequential(skip+1), 10)); + refreshSingle(apibutton, () => setTimeout(() => refreshConsistencyDisplaySequential(skip+1, filter), 10)); } } -function refreshConsistencyDisplayParallel() +function refreshConsistencyDisplayParallel(filter) { - for (let apibutton of $('.selftest_parallel .consistence_ajax_handler').toArray()) + let all = (filter === '') ? $('.selftest_parent .consistence_ajax_handler') : $('.selftest_parallel .consistence_ajax_handler[data-root="'+filter+'"]'); + + for (let apibutton of all.toArray()) { refreshSingle(apibutton, () => {}); } @@ -111,7 +115,13 @@ function refreshSingle(apibutton, then) const filter = $(apibutton).data('filter'); const outdiv = $($(apibutton).data('stid')); - $(apibutton).removeClass('consistency_result_intermed'); + $(apibutton) + .removeClass('consistency_result_intermed') + .removeClass('consistency_result_fin') + .removeClass('consistency_result_ok') + .removeClass('consistency_result_warn') + .removeClass('consistency_result_err'); + $(apibutton).addClass('consistency_result_running'); $.ajax('/api/site::selftest?filter=' + filter) @@ -174,7 +184,24 @@ function queryGitField(dest) $(function() { - for (let elem of $('.selftest_sequential').toArray()) setTimeout(() => refreshConsistencyDisplaySequential(0), 200); - for (let elem of $('.selftest_parallel').toArray()) setTimeout(() => refreshConsistencyDisplayParallel(), 200); + if ($('.selftest_sequential').length > 0) setTimeout(() => refreshConsistencyDisplaySequential(0, "modules"), 200); + + if ($('.selftest_parallel').length > 0) setTimeout(() => refreshConsistencyDisplayParallel("modules"), 200); + for (let elem of $('.admin_ajax_gitfield').toArray()) setTimeout(() => queryGitField(elem), 0); + + $('#btnFullSelftest').on('click', () => + { + $('.consistence_ajax_handler') + .removeClass('consistency_result_fin') + .removeClass('consistency_result_ok') + .removeClass('consistency_result_warn') + .removeClass('consistency_result_err') + .addClass('consistency_result_intermed') + .text(''); + + if ($('.selftest_sequential').length > 0) refreshConsistencyDisplaySequential(0, ""); + if ($('.selftest_parallel').length > 0) refreshConsistencyDisplayParallel(""); + return false; + }); }); \ No newline at end of file diff --git a/www/internals/modules/selftest.php b/www/internals/modules/selftest.php index f8b8656..ddbd34f 100644 --- a/www/internals/modules/selftest.php +++ b/www/internals/modules/selftest.php @@ -174,7 +174,8 @@ class SelfTest implements IWebsiteModule [ 'name' => key_exists($d, self::DISPLAY_NAMES) ? self::DISPLAY_NAMES[$d] : $d, 'filter' => $d.'::*', - 'base' => $d + 'base' => $d, + 'root' => explode('::', $d)[0], ]; } diff --git a/www/pages/admin.php b/www/pages/admin.php index 6214afe..a379f53 100644 --- a/www/pages/admin.php +++ b/www/pages/admin.php @@ -55,13 +55,15 @@ $connected = true; try { $SITE->modules->Database(); } catch (Exception $e) { $c
Self test
-
+ Full Selftest + +
modules->SelfTest()->listMethodGroups() as $group): $stid++; ?> -
- - +
+ +
-
 
+