mirror of
https://github.com/nextcloud/all-in-one.git
synced 2026-05-21 02:40:09 +00:00
aio-interface: cache config by mtime in ConfigurationManager to avoid redundant disk reads
Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/259ee301-d37b-409f-9a09-0cc7d87437fe fix: change configMtime default and reset value from null to 0 Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/8a9ca3ac-8713-4235-aaac-a4496863469b fix: reset config and mtime when file absent or filemtime fails Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/259ee301-d37b-409f-9a09-0cc7d87437fe fix: use null sentinel for configMtime and reset on filemtime failure Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/259ee301-d37b-409f-9a09-0cc7d87437fe fix: restore missing return statement in getConfig() to fix psalm Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/28ac9917-d57b-465f-8e98-dbc75c416ace Co-Authored-By: szaimen <42591237+szaimen@users.noreply.github.com>
This commit is contained in:
committed by
Simon L.
parent
7c40f57f36
commit
2be6039bfd
@@ -12,6 +12,8 @@ class ConfigurationManager
|
||||
|
||||
private array $config = [];
|
||||
|
||||
private int $configMtime = 0;
|
||||
|
||||
private bool $noWrite = false;
|
||||
|
||||
private string $dailyBackupFileCache = '';
|
||||
@@ -299,13 +301,21 @@ class ConfigurationManager
|
||||
|
||||
private function getConfig() : array
|
||||
{
|
||||
if ($this->config === [] && file_exists(DataConst::GetConfigFile()))
|
||||
{
|
||||
$configContent = (string)file_get_contents(DataConst::GetConfigFile());
|
||||
if ($configContent === '') {
|
||||
throw new \RuntimeException("The config file " . DataConst::GetConfigFile() . " is empty. It may have been truncated due to low disk space. Please restore it from a backup.");
|
||||
$configFile = DataConst::GetConfigFile();
|
||||
if (file_exists($configFile)) {
|
||||
$mtime = filemtime($configFile);
|
||||
if ($mtime !== false && $mtime !== $this->configMtime) {
|
||||
$configContent = (string)file_get_contents($configFile);
|
||||
$this->config = json_decode($configContent, true, 512, JSON_THROW_ON_ERROR);
|
||||
$configContent = (string)file_get_contents(DataConst::GetConfigFile());
|
||||
if ($configContent === '') {
|
||||
throw new \RuntimeException("The config file " . DataConst::GetConfigFile() . " is empty. It may have been truncated due to low disk space. Please restore it from a backup.");
|
||||
}
|
||||
$this->configMtime = $mtime;
|
||||
}
|
||||
$this->config = json_decode($configContent, true, 512, JSON_THROW_ON_ERROR);
|
||||
} else {
|
||||
$this->config = [];
|
||||
$this->configMtime = 0;
|
||||
}
|
||||
|
||||
return $this->config;
|
||||
@@ -720,7 +730,14 @@ class ConfigurationManager
|
||||
unlink($tempFile);
|
||||
throw new InvalidSettingConfigurationException("Failed to rename " . $tempFile . " to " . DataConst::GetConfigFile());
|
||||
}
|
||||
$this->config = [];
|
||||
clearstatcache(true, DataConst::GetConfigFile());
|
||||
$mtime = filemtime(DataConst::GetConfigFile());
|
||||
if ($mtime !== false) {
|
||||
$this->configMtime = $mtime;
|
||||
} else {
|
||||
$this->config = [];
|
||||
$this->configMtime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private function getEnvironmentalVariableOrConfig(string $envVariableName, string $configName, string $defaultValue) : string {
|
||||
|
||||
Reference in New Issue
Block a user