fix: reduce unnecessary file writes at startup

This commit is contained in:
2026-07-06 22:40:46 +08:00
parent 2789be852e
commit 2e610bc8ef
2 changed files with 21 additions and 4 deletions
+16 -3
View File
@@ -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()