From 2be6039bfd31ab88b1869bc1f3b009f800b02557 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 19 Apr 2026 15:11:56 +0000 Subject: [PATCH] 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> --- php/src/Data/ConfigurationManager.php | 31 +++++++++++++++++++++------ 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/php/src/Data/ConfigurationManager.php b/php/src/Data/ConfigurationManager.php index 029a377f..5ffa12ba 100644 --- a/php/src/Data/ConfigurationManager.php +++ b/php/src/Data/ConfigurationManager.php @@ -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 {