From 2e610bc8efaeb846a4e57ba7c6179bee78a069dd Mon Sep 17 00:00:00 2001 From: YoursFunny Date: Mon, 6 Jul 2026 15:42:16 +0800 Subject: [PATCH] fix: reduce unnecessary file writes at startup --- deploy/Windows/config.py | 6 +++++- module/webui/config.py | 19 ++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/deploy/Windows/config.py b/deploy/Windows/config.py index 128de50..1e41ecd 100644 --- a/deploy/Windows/config.py +++ b/deploy/Windows/config.py @@ -95,7 +95,8 @@ class DeployConfig(ConfigModel): def read(self): self.config = poor_yaml_read(DEPLOY_TEMPLATE) self.config_template = copy.deepcopy(self.config) - self.config.update(poor_yaml_read(self.file)) + origin = poor_yaml_read(self.file) + self.config.update(origin) for key, value in self.config.items(): if hasattr(self, key): @@ -103,6 +104,9 @@ class DeployConfig(ConfigModel): self.config_redirect() + if self.config != origin: + self.write() + def write(self): poor_yaml_write(self.config, self.file) diff --git a/module/webui/config.py b/module/webui/config.py index 0df5f05..64e48c6 100644 --- a/module/webui/config.py +++ b/module/webui/config.py @@ -1,3 +1,5 @@ +import copy + from filelock import FileLock from deploy.Windows.config import DeployConfig as _DeployConfig @@ -31,7 +33,9 @@ class DeployConfig(_DeployConfig): Read and update deploy config, copy `self.configs` to properties. """ self.config = poor_yaml_read_with_lock(DEPLOY_TEMPLATE) - self.config.update(poor_yaml_read_with_lock(self.file)) + self.config_template = copy.deepcopy(self.config) + origin = poor_yaml_read_with_lock(self.file) + self.config.update(origin) for key, value in self.config.items(): if hasattr(self, key): @@ -39,6 +43,9 @@ class DeployConfig(_DeployConfig): self.config_redirect() + if self.config != origin: + self.write() + def write(self): """ Write `self.config` into deploy config. @@ -51,5 +58,11 @@ class DeployConfig(_DeployConfig): """ super().__setattr__(key, value) if key[0].isupper() and key in self.config: - self.config[key] = value - self.write() + if key in self.config: + before = self.config[key] + if before != value: + self.config[key] = value + self.write() + else: + self.config[key] = value + self.write()