From a3d6062476dde7fecfb559bb366a3f22cb6ead57 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Mon, 18 Feb 2019 08:51:38 +0100 Subject: [PATCH 1/3] check if value is set get basepath with config instead cache --- src/App.php | 2 +- src/Core/Config/Adapter/JITConfigAdapter.php | 18 ++++++++++++++++-- src/Core/Config/Configuration.php | 6 ++++++ src/Core/Worker.php | 2 ++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/App.php b/src/App.php index f41d486b5..f48abcf9c 100644 --- a/src/App.php +++ b/src/App.php @@ -219,7 +219,7 @@ class App $this->logger = $logger; $this->config = $config; $this->profiler = $profiler; - $this->basePath = $this->config->getCache()->get('system', 'basepath'); + $this->basePath = $this->config->get('system', 'basepath'); if (!Core\System::isDirectoryUsable($this->basePath, false)) { throw new Exception('Basepath \'' . $this->basePath . '\' isn\'t usable.'); diff --git a/src/Core/Config/Adapter/JITConfigAdapter.php b/src/Core/Config/Adapter/JITConfigAdapter.php index 95211777f..0c94f8127 100644 --- a/src/Core/Config/Adapter/JITConfigAdapter.php +++ b/src/Core/Config/Adapter/JITConfigAdapter.php @@ -1,6 +1,7 @@ in_db[$cat][$key] = true; - return $value; + if ($key === 'last_worker_execution') { + Logger::alert('catchmeifyou', ['store' => $value, 'in_db' => $this->in_db[$cat][$key]]); + } + + if (isset($value) && $value !== '') { + $this->in_db[$cat][$key] = true; + return $value; + } else { + $this->in_db[$cat][$key] = false; + return '!!'; + } } else { $this->in_db[$cat][$key] = false; @@ -89,6 +99,10 @@ class JITConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAdapte $this->in_db[$cat][$key] = false; } + if ($key === 'last_worker_execution') { + Logger::alert('catchmeifyou', ['db' => $dbvalue, 'store' => $stored, 'in_db' => $this->in_db[$cat][$key]]); + } + if (($stored === $dbvalue) && $this->in_db[$cat][$key]) { return true; } diff --git a/src/Core/Config/Configuration.php b/src/Core/Config/Configuration.php index 2ac0da0ad..48220c2de 100644 --- a/src/Core/Config/Configuration.php +++ b/src/Core/Config/Configuration.php @@ -2,6 +2,8 @@ namespace Friendica\Core\Config; +use Friendica\Core\Logger; + /** * This class is responsible for all system-wide configuration values in Friendica * There are two types of storage @@ -114,6 +116,10 @@ class Configuration */ public function set($cat, $key, $value) { + if ($key === 'last_worker_execution') { + Logger::alert('catchmeifyou', ['value' => $value]); + } + // set the cache first $cached = $this->configCache->set($cat, $key, $value); diff --git a/src/Core/Worker.php b/src/Core/Worker.php index dff60e9fa..c5d60f14d 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -277,6 +277,8 @@ class Worker $age = (time() - self::$last_update) / 60; self::$last_update = time(); + Logger::alert('last_update', ['age' => $age, 'last_update' => self::$last_update]); + if ($age > 1) { $stamp = (float)microtime(true); DBA::update('workerqueue', ['executed' => DateTimeFormat::utcNow()], ['pid' => $mypid, 'done' => false]); From 86aaa6565e4630ecbc4a70eb3bb3faabaea5b86c Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Mon, 18 Feb 2019 11:18:05 +0100 Subject: [PATCH 2/3] Fixing saveLog() --- src/Core/Worker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Worker.php b/src/Core/Worker.php index c5d60f14d..13db8d97e 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -441,7 +441,7 @@ class Worker Logger::log("Process ".$mypid." - Prio ".$queue["priority"]." - ID ".$queue["id"].": ".$funcname." - done in ".number_format($duration, 4)." seconds. Process PID: ".$new_process_id); - $a->getProfiler()->saveLog("ID " . $queue["id"] . ": " . $funcname); + $a->getProfiler()->saveLog($a->getLogger(), "ID " . $queue["id"] . ": " . $funcname); $cooldown = Config::get("system", "worker_cooldown", 0); From f53610791184ad8a567fb6a61cb3ad437519c2a4 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Mon, 18 Feb 2019 11:27:51 +0100 Subject: [PATCH 3/3] Fixing value check for configuration --- src/Core/Config/Adapter/JITConfigAdapter.php | 19 +++---------------- src/Core/Config/Adapter/JITPConfigAdapter.php | 13 +++++++------ .../Config/Adapter/PreloadConfigAdapter.php | 9 +++++---- .../Config/Adapter/PreloadPConfigAdapter.php | 7 ++++--- src/Core/Config/Configuration.php | 6 ------ src/Core/Worker.php | 2 -- 6 files changed, 19 insertions(+), 37 deletions(-) diff --git a/src/Core/Config/Adapter/JITConfigAdapter.php b/src/Core/Config/Adapter/JITConfigAdapter.php index 0c94f8127..5d06dc2b3 100644 --- a/src/Core/Config/Adapter/JITConfigAdapter.php +++ b/src/Core/Config/Adapter/JITConfigAdapter.php @@ -1,7 +1,6 @@ $value, 'in_db' => $this->in_db[$cat][$key]]); - } - if (isset($value) && $value !== '') { $this->in_db[$cat][$key] = true; return $value; - } else { - $this->in_db[$cat][$key] = false; - return '!!'; } - } else { - - $this->in_db[$cat][$key] = false; - return '!!'; } + + $this->in_db[$cat][$key] = false; + return '!!'; } /** @@ -99,10 +90,6 @@ class JITConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAdapte $this->in_db[$cat][$key] = false; } - if ($key === 'last_worker_execution') { - Logger::alert('catchmeifyou', ['db' => $dbvalue, 'store' => $stored, 'in_db' => $this->in_db[$cat][$key]]); - } - if (($stored === $dbvalue) && $this->in_db[$cat][$key]) { return true; } diff --git a/src/Core/Config/Adapter/JITPConfigAdapter.php b/src/Core/Config/Adapter/JITPConfigAdapter.php index c5f3a381e..d3c38623b 100644 --- a/src/Core/Config/Adapter/JITPConfigAdapter.php +++ b/src/Core/Config/Adapter/JITPConfigAdapter.php @@ -57,13 +57,14 @@ class JITPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfigAdap // manage array value $value = (preg_match("|^a:[0-9]+:{.*}$|s", $pconfig['v']) ? unserialize($pconfig['v']) : $pconfig['v']); - $this->in_db[$uid][$cat][$key] = true; - return $value; - } else { - - $this->in_db[$uid][$cat][$key] = false; - return '!!'; + if (isset($value) && $value !== '') { + $this->in_db[$uid][$cat][$key] = true; + return $value; + } } + + $this->in_db[$uid][$cat][$key] = false; + return '!!'; } /** diff --git a/src/Core/Config/Adapter/PreloadConfigAdapter.php b/src/Core/Config/Adapter/PreloadConfigAdapter.php index fa691a16d..b1866a259 100644 --- a/src/Core/Config/Adapter/PreloadConfigAdapter.php +++ b/src/Core/Config/Adapter/PreloadConfigAdapter.php @@ -55,11 +55,12 @@ class PreloadConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAd // manage array value $value = (preg_match("|^a:[0-9]+:{.*}$|s", $config['v']) ? unserialize($config['v']) : $config['v']); - return $value; - } else { - - return '!!'; + if (isset($value) && $value !== '') { + return $value; + } } + + return '!!'; } /** diff --git a/src/Core/Config/Adapter/PreloadPConfigAdapter.php b/src/Core/Config/Adapter/PreloadPConfigAdapter.php index e79a4a1e3..857f2b176 100644 --- a/src/Core/Config/Adapter/PreloadPConfigAdapter.php +++ b/src/Core/Config/Adapter/PreloadPConfigAdapter.php @@ -71,10 +71,11 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig // manage array value $value = (preg_match("|^a:[0-9]+:{.*}$|s", $config['v']) ? unserialize($config['v']) : $config['v']); - return $value; - } else { - return '!!'; + if (isset($value) && $value !== '') { + return $value; + } } + return '!!'; } /** diff --git a/src/Core/Config/Configuration.php b/src/Core/Config/Configuration.php index 48220c2de..2ac0da0ad 100644 --- a/src/Core/Config/Configuration.php +++ b/src/Core/Config/Configuration.php @@ -2,8 +2,6 @@ namespace Friendica\Core\Config; -use Friendica\Core\Logger; - /** * This class is responsible for all system-wide configuration values in Friendica * There are two types of storage @@ -116,10 +114,6 @@ class Configuration */ public function set($cat, $key, $value) { - if ($key === 'last_worker_execution') { - Logger::alert('catchmeifyou', ['value' => $value]); - } - // set the cache first $cached = $this->configCache->set($cat, $key, $value); diff --git a/src/Core/Worker.php b/src/Core/Worker.php index 13db8d97e..4007a7923 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -277,8 +277,6 @@ class Worker $age = (time() - self::$last_update) / 60; self::$last_update = time(); - Logger::alert('last_update', ['age' => $age, 'last_update' => self::$last_update]); - if ($age > 1) { $stamp = (float)microtime(true); DBA::update('workerqueue', ['executed' => DateTimeFormat::utcNow()], ['pid' => $mypid, 'done' => false]);