mirror of
https://github.com/TheFunny/ArisuAutoSweeper
synced 2026-10-10 17:52:09 +00:00
fix: reduce unnecessary file writes at startup
This commit is contained in:
@@ -95,7 +95,8 @@ class DeployConfig(ConfigModel):
|
|||||||
def read(self):
|
def read(self):
|
||||||
self.config = poor_yaml_read(DEPLOY_TEMPLATE)
|
self.config = poor_yaml_read(DEPLOY_TEMPLATE)
|
||||||
self.config_template = copy.deepcopy(self.config)
|
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():
|
for key, value in self.config.items():
|
||||||
if hasattr(self, key):
|
if hasattr(self, key):
|
||||||
@@ -103,6 +104,9 @@ class DeployConfig(ConfigModel):
|
|||||||
|
|
||||||
self.config_redirect()
|
self.config_redirect()
|
||||||
|
|
||||||
|
if self.config != origin:
|
||||||
|
self.write()
|
||||||
|
|
||||||
def write(self):
|
def write(self):
|
||||||
poor_yaml_write(self.config, self.file)
|
poor_yaml_write(self.config, self.file)
|
||||||
|
|
||||||
|
|||||||
+16
-3
@@ -1,3 +1,5 @@
|
|||||||
|
import copy
|
||||||
|
|
||||||
from filelock import FileLock
|
from filelock import FileLock
|
||||||
|
|
||||||
from deploy.Windows.config import DeployConfig as _DeployConfig
|
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.
|
Read and update deploy config, copy `self.configs` to properties.
|
||||||
"""
|
"""
|
||||||
self.config = poor_yaml_read_with_lock(DEPLOY_TEMPLATE)
|
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():
|
for key, value in self.config.items():
|
||||||
if hasattr(self, key):
|
if hasattr(self, key):
|
||||||
@@ -39,6 +43,9 @@ class DeployConfig(_DeployConfig):
|
|||||||
|
|
||||||
self.config_redirect()
|
self.config_redirect()
|
||||||
|
|
||||||
|
if self.config != origin:
|
||||||
|
self.write()
|
||||||
|
|
||||||
def write(self):
|
def write(self):
|
||||||
"""
|
"""
|
||||||
Write `self.config` into deploy config.
|
Write `self.config` into deploy config.
|
||||||
@@ -51,5 +58,11 @@ class DeployConfig(_DeployConfig):
|
|||||||
"""
|
"""
|
||||||
super().__setattr__(key, value)
|
super().__setattr__(key, value)
|
||||||
if key[0].isupper() and key in self.config:
|
if key[0].isupper() and key in self.config:
|
||||||
self.config[key] = value
|
if key in self.config:
|
||||||
self.write()
|
before = self.config[key]
|
||||||
|
if before != value:
|
||||||
|
self.config[key] = value
|
||||||
|
self.write()
|
||||||
|
else:
|
||||||
|
self.config[key] = value
|
||||||
|
self.write()
|
||||||
|
|||||||
Reference in New Issue
Block a user