mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-07-23 04:09:04 +03:00
/api/config/set and camera deletion re-parse yaml into a fresh FrigateConfig and swap it in, then re-layered the persisted runtime toggle overrides so a camera the user turned off wouldn't come back on. That re-layer ran apply_runtime_state, which replays each override through the command handlers, so every save re-published a ZMQ config update, a retained MQTT state message, and a runtime-state disk write for every camera with a stored toggle. All of it was redundant: the worker processes were never swapped and still hold the live toggle values, so only the in-process config object the API and dispatcher read was out of date. The extra traffic churned the retained MQTT topics, amplified disk writes, and co-drained enabled updates with other topics on the config socket. Add Dispatcher.reapply_runtime_state_to_config, which corrects only the swapped-in config object, mirroring the field mutations and gates of the _on_*_command handlers with no ZMQ, MQTT, or disk writes. swap_runtime_config now calls it instead of apply_runtime_state; apply_runtime_state is unchanged and still used at startup, where the workers genuinely must be told.
36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
"""Shared helpers for applying a freshly parsed config to the running app."""
|
|
|
|
from fastapi import FastAPI
|
|
|
|
from frigate.config import FrigateConfig
|
|
|
|
|
|
def swap_runtime_config(app: FastAPI, config: FrigateConfig) -> None:
|
|
"""Point every long-lived collaborator at a newly parsed config object.
|
|
|
|
Both /api/config/set and camera deletion re-parse yaml into a fresh
|
|
FrigateConfig and must rebind the same set of references, or the API and
|
|
the dispatcher drift onto different objects (the API reports one camera
|
|
state while the dispatcher acts on another). Runtime toggle overrides are
|
|
re-layered last: the swap rebuilt every camera from yaml, so without this a
|
|
camera the user turned off would silently come back on.
|
|
"""
|
|
app.frigate_config = config
|
|
app.genai_manager.update_config(config)
|
|
|
|
if app.profile_manager is not None:
|
|
app.profile_manager.update_config(config)
|
|
|
|
if app.stats_emitter is not None:
|
|
app.stats_emitter.config = config
|
|
|
|
if app.dispatcher is not None:
|
|
app.dispatcher.config = config
|
|
|
|
for comm in app.dispatcher.comms:
|
|
comm.config = config
|
|
|
|
# workers still hold the live toggle values, so correct only the
|
|
# config object here rather than re-broadcasting every override
|
|
app.dispatcher.reapply_runtime_state_to_config()
|