perf(web): deduplicate control plane gate state
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled

This commit is contained in:
mes123456
2026-09-03 15:35:18 +08:00
parent b29d4c88a7
commit d602a13e2b
7 changed files with 434 additions and 29 deletions

View File

@@ -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)