perf(web): deduplicate control plane gate state
This commit is contained in:
@@ -32,6 +32,14 @@ def now() -> str:
|
||||
|
||||
def write_json(path: Path, value: dict) -> None:
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
try:
|
||||
current = json.loads(path.read_text(encoding="utf-8"))
|
||||
stable_current = {key: item for key, item in current.items() if key != "updatedAt"}
|
||||
stable_next = {key: item for key, item in value.items() if key != "updatedAt"}
|
||||
if stable_current == stable_next:
|
||||
return
|
||||
except (OSError, json.JSONDecodeError):
|
||||
pass
|
||||
temporary = path.with_suffix(path.suffix + f".tmp-{os.getpid()}")
|
||||
temporary.write_text(json.dumps(value, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
||||
temporary.replace(path)
|
||||
|
||||
Reference in New Issue
Block a user