Skip to content

aio-interface: cache config by mtime in ConfigurationManager to avoid redundant disk reads#7956

Draft
Copilot wants to merge 1 commit into
mainfrom
copilot/cache-config-in-configurationmanager
Draft

aio-interface: cache config by mtime in ConfigurationManager to avoid redundant disk reads#7956
Copilot wants to merge 1 commit into
mainfrom
copilot/cache-config-in-configurationmanager

Conversation

Copilot AI commented Apr 19, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI requested a review from szaimen April 19, 2026 15:14
@szaimen szaimen added 3. to review Waiting for reviews enhancement New feature or request labels Apr 19, 2026
@szaimen szaimen added this to the next milestone Apr 19, 2026
@szaimen szaimen requested a review from pabzm April 20, 2026 12:54
@szaimen szaimen marked this pull request as ready for review April 20, 2026 12:54
@szaimen szaimen changed the title feat: cache config by mtime in ConfigurationManager to avoid redundant disk reads aio-interface: cache config by mtime in ConfigurationManager to avoid redundant disk reads Apr 20, 2026
@szaimen szaimen force-pushed the copilot/cache-config-in-configurationmanager branch from af77490 to f47da6c Compare April 20, 2026 12:54
@szaimen szaimen force-pushed the copilot/cache-config-in-configurationmanager branch from d59c8a2 to 8b8f0f1 Compare April 20, 2026 13:06
pabzm
pabzm previously approved these changes Apr 20, 2026

@pabzm pabzm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks! 👍

… 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>
@szaimen szaimen force-pushed the copilot/cache-config-in-configurationmanager branch from 8b8f0f1 to 2be6039 Compare April 21, 2026 12:18
@szaimen

szaimen commented Apr 21, 2026

Copy link
Copy Markdown
Collaborator

@pabzm please review another time. I had to rebase and change the implementation due to the merge of #7888

@szaimen szaimen requested a review from pabzm April 21, 2026 16:02
Comment on lines +309 to +313
$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.");
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 310 is useless, maybe an artefact from rebasing?

And parsing the content should happen after it was checked to be non-empty, I'd say.

And while we're at it, let's catch possible JSON parsing errors to produce helpful error messages in the log, ok?

Suggested change
$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.");
}
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.");
}
try {
$this->config = json_decode($configContent, true, 512, JSON_THROW_ON_ERROR);
} catch (JsonException $exc) {
throw new \RuntimeException("The config file " . DataConst::GetConfigFile() . " could not be parsed as JSON. Please check its contents and maybe restore it from a backup. (Original error: {$exc->message})");
}

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);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$mtime = filemtime($configFile);
clearstatcache(true, DataConst::GetConfigFile());
$mtime = filemtime($configFile);

@szaimen

szaimen commented Apr 24, 2026

Copy link
Copy Markdown
Collaborator

@pabzm and me discussed we will work on finishing this later

@szaimen szaimen added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Apr 24, 2026
@szaimen

szaimen commented Apr 24, 2026

Copy link
Copy Markdown
Collaborator

in the case of starttransaction it will make the io worse as it still will read the mtime every time...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2. developing Work in progress enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants