1
0
mirror of https://gitee.com/sui-feng-cb/AzurLaneAutoScript1 synced 2026-03-11 20:58:19 +08:00

Fix: [ALAS] Reduce unnecessary file writes at startup

This commit is contained in:
LmeSzinc
2025-02-25 00:43:27 +08:00
parent 4f070157a1
commit ec2c1959f5
3 changed files with 30 additions and 9 deletions

View File

@@ -1,4 +1,5 @@
from typing import Optional, Union
import copy
from filelock import FileLock
from deploy.config import DeployConfig as _DeployConfig
@@ -32,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):
@@ -40,6 +43,9 @@ class DeployConfig(_DeployConfig):
self.config_redirect()
if self.config != origin:
self.write()
def write(self):
"""
Write `self.config` into deploy config.
@@ -52,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()