Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/survey_server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBjoern Schiessle <bjoern@schiessle.org>2018-08-03 12:25:45 +0300
committerBjoern Schiessle <bjoern@schiessle.org>2018-08-03 12:31:39 +0300
commitf16c62cfbf6272b49d0a5d9777aa85c464c3468c (patch)
tree5db7f24b84b7c9baeafb9b98d19e0104ee78dda0 /lib
parent7206d195c1d7b350babaa2d9db89b77fe2c1b894 (diff)
only compute one set of date per run
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/BackgroundJobs/ComputeStatistics.php35
1 files changed, 29 insertions, 6 deletions
diff --git a/lib/BackgroundJobs/ComputeStatistics.php b/lib/BackgroundJobs/ComputeStatistics.php
index 3fe94f5..e328ca2 100644
--- a/lib/BackgroundJobs/ComputeStatistics.php
+++ b/lib/BackgroundJobs/ComputeStatistics.php
@@ -50,16 +50,39 @@ class ComputeStatistics extends TimedJob {
$this->connection = $connection ? $connection : \OC::$server->getDatabaseConnection();
$this->config = $config = $config ? $config : \OC::$server->getConfig();
$this->evaluateStatistics = $evaluateStatistics ? $evaluateStatistics : new EvaluateStatistics();
- $this->setInterval(24 * 60 * 60);
+ $this->setInterval(60 * 60);
}
protected function run($argument) {
- $result = [];
- $result['instances'] = $this->getNumberOfInstances();
- $result['categories'] = $this->getStatisticsOfCategories();
- $result['apps'] = $this->getApps();
- $this->config->setAppValue('survey_server', 'evaluated_statistics', json_encode($result));
+ $lastResult = $this->config->getAppValue('survey_server', 'evaluated_statistics', []);
+ $newResult = json_decode($lastResult, true);
+
+ if (!isset($newResult['lastRun'])) {
+ $newResult['lastRun'] = [];
+ }
+
+ $lastRun = [];
+ $lastRun['categories'] = isset($newResult['lastRun']['categories']) ? (int)$newResult['lastRun']['categories'] : 0;
+ $lastRun['apps'] = isset($newResult['lastRun']['apps']) ? (int)$newResult['lastRun']['apps'] : 0;
+
+ $selected = array_keys($lastRun, min($lastRun));
+
+ // this is fast, so let's run this always
+ $newResult['instances'] = $this->getNumberOfInstances();
+
+ switch ($selected[0]) {
+ case 'categories':
+ $newResult['categories'] = $this->getStatisticsOfCategories();
+ $newResult['lastRun']['categories'] = time();
+ break;
+ case 'apps':
+ $newResult['apps'] = $this->getApps();
+ $newResult['lastRun']['apps'] = time();
+ break;
+ }
+
+ $this->config->setAppValue('survey_server', 'evaluated_statistics', json_encode($newResult));
}
/**