fix(config-sync): 修复全量同步时空配置不清理旧数据的bug
问题描述: - 当sync_mode=full且incoming_ids为空时,条件判断失败 - 导致旧的孤儿ROI配置残留在本地数据库 - 后续配置更新时尝试启动孤儿ROI对应的摄像头,产生警告 根本原因: - line 889: if self._db_manager and incoming_ids: - 当incoming_ids为空列表时,条件判断为False - 跳过了清理旧配置的逻辑 修复方案: - 移除incoming_ids的条件判断 - 全量同步时始终执行清理逻辑 - incoming_ids为空时,清除所有旧配置(符合全量同步语义) - incoming_ids不为空时,清除不在列表中的旧配置 附加工具: - cleanup_orphan_rois.py: 清理当前残留的孤儿ROI记录 影响: - 修复配置同步逻辑bug - 避免孤儿ROI警告 - 提高配置同步的可靠性 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -886,15 +886,17 @@ class ConfigSyncManager:
|
||||
sync_mode = config_data.get("sync_mode", "partial")
|
||||
if sync_mode == "full":
|
||||
self._init_database()
|
||||
if self._db_manager and incoming_ids:
|
||||
if self._db_manager:
|
||||
try:
|
||||
existing = self._db_manager.get_all_camera_configs()
|
||||
for cam in existing:
|
||||
old_id = cam.get("camera_id")
|
||||
# 如果incoming_ids为空,清除所有旧配置
|
||||
# 如果incoming_ids不为空,清除不在列表中的旧配置
|
||||
if old_id and old_id not in incoming_ids:
|
||||
self._clear_rois_for_camera_ids([old_id])
|
||||
self._db_manager.delete_camera_config(old_id)
|
||||
logger.info(f"[EDGE] 清除不在推送列表中的旧摄像头: {old_id}")
|
||||
logger.info(f"[EDGE] 全量同步清除旧摄像头: {old_id}")
|
||||
except Exception as e:
|
||||
logger.warning(f"[EDGE] 清理旧摄像头失败: {e}")
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user