1
0

do not run expensive selftest on every /admin site visit

This commit is contained in:
Mike Schwörer 2020-12-02 09:06:10 +01:00
parent 8207ece48c
commit f3a29eac31
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
3 changed files with 44 additions and 14 deletions

View File

@ -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; let i = 0;
for (let apibutton of $('.selftest_sequential .consistence_ajax_handler').toArray()) for (let apibutton of all.toArray())
{ {
if (i++ !== skip) continue; 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, () => {}); refreshSingle(apibutton, () => {});
} }
@ -111,7 +115,13 @@ function refreshSingle(apibutton, then)
const filter = $(apibutton).data('filter'); const filter = $(apibutton).data('filter');
const outdiv = $($(apibutton).data('stid')); 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'); $(apibutton).addClass('consistency_result_running');
$.ajax('/api/site::selftest?filter=' + filter) $.ajax('/api/site::selftest?filter=' + filter)
@ -174,7 +184,24 @@ function queryGitField(dest)
$(function() $(function()
{ {
for (let elem of $('.selftest_sequential').toArray()) setTimeout(() => refreshConsistencyDisplaySequential(0), 200); if ($('.selftest_sequential').length > 0) setTimeout(() => refreshConsistencyDisplaySequential(0, "modules"), 200);
for (let elem of $('.selftest_parallel').toArray()) setTimeout(() => refreshConsistencyDisplayParallel(), 200);
if ($('.selftest_parallel').length > 0) setTimeout(() => refreshConsistencyDisplayParallel("modules"), 200);
for (let elem of $('.admin_ajax_gitfield').toArray()) setTimeout(() => queryGitField(elem), 0); 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;
});
}); });

View File

@ -174,7 +174,8 @@ class SelfTest implements IWebsiteModule
[ [
'name' => key_exists($d, self::DISPLAY_NAMES) ? self::DISPLAY_NAMES[$d] : $d, 'name' => key_exists($d, self::DISPLAY_NAMES) ? self::DISPLAY_NAMES[$d] : $d,
'filter' => $d.'::*', 'filter' => $d.'::*',
'base' => $d 'base' => $d,
'root' => explode('::', $d)[0],
]; ];
} }

View File

@ -55,13 +55,15 @@ $connected = true; try { $SITE->modules->Database(); } catch (Exception $e) { $c
<div class="bc_header">Self test</div> <div class="bc_header">Self test</div>
<div class="bc_data"> <div class="bc_data">
<div class="keyvaluelist kvl_200 selftest_parent <?php echo $SITE->isProd() ? 'selftest_parallel' : 'selftest_sequential' ?>"> <a id="btnFullSelftest" class="button" href="#">Full Selftest</a>
<div class="keyvaluelist kvl_200 selftest_parent <?= ($SITE->isProd() ? 'selftest_parallel' : 'selftest_sequential') ?>">
<?php $stid=1000; foreach ($SITE->modules->SelfTest()->listMethodGroups() as $group): $stid++; ?> <?php $stid=1000; foreach ($SITE->modules->SelfTest()->listMethodGroups() as $group): $stid++; ?>
<div class="selftest_tabchild" onclick="showSelfTestOutput('#selftest_tab_<?php echo $stid; ?>', '#selftest_out_<?php echo $stid; ?>')"> <div class="selftest_tabchild" onclick="showSelfTestOutput('#selftest_tab_<?= $stid; ?>', '#selftest_out_<?= $stid; ?>')">
<span><?php echo $group['name']; ?></span> <span><?= $group['name']; ?></span>
<span class='consistency_result consistency_result_intermed consistence_ajax_handler' id="selftest_tab_<?php echo $stid; ?>" data-filter="<?php echo $group['filter']; ?>" data-stid="#selftest_out_<?php echo $stid; ?>"></span> <span class='consistency_result consistency_result_intermed consistence_ajax_handler' id="selftest_tab_<?= $stid; ?>" data-filter="<?= $group['filter']; ?>" data-stid="#selftest_out_<?= $stid; ?>" data-root="<?= $group['root'] ?>"></span>
</div> </div>
<div class="selftest_outputchild generic_nodisplay" id="selftest_out_<?php echo $stid; ?>">&nbsp;</div> <div class="selftest_outputchild generic_nodisplay" id="selftest_out_<?= $stid; ?>">&nbsp;</div>
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
<br/> <br/>