mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-26 05:32:59 +00:00
Don't load the stats index if it's not needed
This commit is contained in:
parent
d3e83a0aea
commit
34fb821804
3 changed files with 21 additions and 6 deletions
|
@ -6,8 +6,8 @@ This file holds the changelog for Pepperminty Wiki. This is the master list of t
|
||||||
## Changed
|
## Changed
|
||||||
- Improved the search indexing system performance - again
|
- Improved the search indexing system performance - again
|
||||||
- Another search index rebuild is required
|
- Another search index rebuild is required
|
||||||
- Don't generate the list of pages for the datalist if it isn't going to be displayed - especially noticeable on wikis with lots of pages
|
- Optimisation: Don't generate the list of pages for the datalist if it isn't going to be displayed (especially noticeable on wikis with lots of pages)
|
||||||
-
|
- Optimisation: Don't load the statistics index if it's not needed (also esp. noticeable on wikis with lots of pages)
|
||||||
|
|
||||||
## v0.20
|
## v0.20
|
||||||
_Just 1 change since the previous beta release._
|
_Just 1 change since the previous beta release._
|
||||||
|
|
|
@ -145,7 +145,7 @@
|
||||||
"version": "0.2.2",
|
"version": "0.2.2",
|
||||||
"author": "Starbeamrainbowlabs",
|
"author": "Starbeamrainbowlabs",
|
||||||
"description": "An extensible statistics calculation system. Comes with a range of built-in statistics, but can be extended by other modules too.",
|
"description": "An extensible statistics calculation system. Comes with a range of built-in statistics, but can be extended by other modules too.",
|
||||||
"lastupdate": 1568296731,
|
"lastupdate": 1575837611,
|
||||||
"optional": false,
|
"optional": false,
|
||||||
"extra_data": []
|
"extra_data": []
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
register_module([
|
register_module([
|
||||||
"name" => "Statistics",
|
"name" => "Statistics",
|
||||||
"version" => "0.2.2",
|
"version" => "0.3",
|
||||||
"author" => "Starbeamrainbowlabs",
|
"author" => "Starbeamrainbowlabs",
|
||||||
"description" => "An extensible statistics calculation system. Comes with a range of built-in statistics, but can be extended by other modules too.",
|
"description" => "An extensible statistics calculation system. Comes with a range of built-in statistics, but can be extended by other modules too.",
|
||||||
"id" => "feature-stats",
|
"id" => "feature-stats",
|
||||||
|
@ -239,15 +239,23 @@ register_module([
|
||||||
*/
|
*/
|
||||||
function update_statistics($update_all = false, $force = false)
|
function update_statistics($update_all = false, $force = false)
|
||||||
{
|
{
|
||||||
global $settings, $statistic_calculators;
|
global $settings, $paths, $statistic_calculators;
|
||||||
|
|
||||||
|
$stats_mtime = filemtime($paths->statsindex);
|
||||||
|
|
||||||
// Clear the existing statistics if we are asked to recalculate them all
|
// Clear the existing statistics if we are asked to recalculate them all
|
||||||
if($force)
|
if($force)
|
||||||
stats_save(new stdClass());
|
stats_save(new stdClass());
|
||||||
|
// If the stats index exists and has been modified recently, then don't
|
||||||
|
// even bother to load it
|
||||||
|
// This is an important optimisation, because json_decode is *slow*
|
||||||
|
else if(file_exists($paths->statsindex) && time() - $stats_mtime < $settings->stats_update_interval)
|
||||||
|
return;
|
||||||
|
|
||||||
$stats = stats_load();
|
$stats = stats_load();
|
||||||
|
|
||||||
$start_time = microtime(true);
|
$start_time = microtime(true);
|
||||||
|
$ran_out_of_time = false;
|
||||||
$stats_updated = 0;
|
$stats_updated = 0;
|
||||||
foreach($statistic_calculators as $stat_id => $stat_calculator)
|
foreach($statistic_calculators as $stat_id => $stat_calculator)
|
||||||
{
|
{
|
||||||
|
@ -274,8 +282,11 @@ function update_statistics($update_all = false, $force = false)
|
||||||
|
|
||||||
$stats_updated++;
|
$stats_updated++;
|
||||||
|
|
||||||
if(!$update_all && microtime(true) - $start_time >= $settings->stats_update_processingtime)
|
// Check to make sure we haven't run out of time to update the statistics this session
|
||||||
|
if(!$update_all && microtime(true) - $start_time >= $settings->stats_update_processingtime) {
|
||||||
|
$ran_out_of_time = true;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
header("x-stats-recalculated: $stats_updated");
|
header("x-stats-recalculated: $stats_updated");
|
||||||
|
@ -283,6 +294,10 @@ function update_statistics($update_all = false, $force = false)
|
||||||
header("x-stats-calctime: " . round((microtime(true) - $start_time)*1000, 3) . "ms");
|
header("x-stats-calctime: " . round((microtime(true) - $start_time)*1000, 3) . "ms");
|
||||||
|
|
||||||
stats_save($stats);
|
stats_save($stats);
|
||||||
|
// If we ran out of time, reset the mtime for performance reasons (see the
|
||||||
|
// beginning of this function)
|
||||||
|
if($ran_out_of_time)
|
||||||
|
touch($paths->statsindex, $stats_mtime);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue