修改问题

This commit is contained in:
strepsiades
2026-04-01 17:04:26 +08:00
parent 7c49df94fc
commit 9a3a34c58b
10 changed files with 119 additions and 29 deletions
+8
View File
@@ -78,6 +78,14 @@ class DataCollection:
# node_id 不变但 data_id 变更,清理旧索引
self._data_id_to_node_id.pop(old_node.data_id, None)
stale_data_ids = [
data_id
for data_id, existing_node_id in self._data_id_to_node_id.items()
if existing_node_id == node.node_id and data_id != node.data_id
]
for stale_data_id in stale_data_ids:
self._data_id_to_node_id.pop(stale_data_id, None)
if node.data_id and node.data_id != "":
existing_node_id = self._data_id_to_node_id.get(node.data_id)
if existing_node_id is not None and existing_node_id != node.node_id:
@@ -315,14 +315,19 @@ class ProjectDetailApiHandler(BaseApiHandler):
existing_by_pair = self._find_existing_by_project_key(project_id=project_id, key=key)
if existing_by_pair is not None:
if loaded_data_id and existing_by_pair.data_id != loaded_data_id:
with existing_by_pair.allow_core_state_write("project_detail_pair_rebind"):
existing_by_pair.data_id = loaded_data_id
existing_by_pair.set_data(data)
existing_by_pair.set_origin_data(data)
if project_id:
existing_by_pair.context["project_id"] = project_id
return existing_by_pair
if loaded_data_id and existing_by_pair.data_id == loaded_data_id:
existing_by_pair.set_data(data)
existing_by_pair.set_origin_data(data)
if project_id:
existing_by_pair.context["project_id"] = project_id
return existing_by_pair
existing_data_id = existing_by_pair.data_id or "<empty>"
loaded_data_id_text = loaded_data_id or "<empty>"
raise RuntimeError(
"project_detail_data load conflict: "
f"project_id={project_id}, key={key}, existing_data_id={existing_data_id}, loaded_data_id={loaded_data_id_text}"
)
node = self._create_basic_node(data, depend_ids=[])
if project_id:
@@ -157,10 +157,24 @@ class FullSyncPipeline:
created = await strategy.create()
self._logger.info(f"✅ Strategy create: {node_type} (created={len(created)})")
created_local_node_ids = {
node.node_id for node in created if self.local_collection.get_by_node_id(node.node_id) is not None
}
created_remote_node_ids = {
node.node_id for node in created if self.remote_collection.get_by_node_id(node.node_id) is not None
}
create_written = await self.commit_creates(node_type)
await self.normalize_create_success_to_update_entry(node_type)
if create_written:
await self._reload_node_type(node_type, reason="create wrote data")
await refresh_bind_data_id(
node_type=node_type,
local_collection=self.local_collection,
remote_collection=self.remote_collection,
binding_manager=self.binding_manager,
local_node_ids=created_local_node_ids,
remote_node_ids=created_remote_node_ids,
)
updated = await strategy.update()
self._logger.info(f"✅ Strategy update: {node_type} (updated={len(updated)})")
@@ -115,7 +115,9 @@ async def refresh_bind_data_id(
continue
remote_node_id = local_to_remote.get(local_node.node_id)
remote_node = remote_collection.get_by_node_id(remote_node_id) if remote_node_id else None
if remote_node and remote_node.data_id:
local_status = getattr(local_node.status, "value", None)
remote_status = getattr(remote_node.status, "value", None) if remote_node is not None else None
if local_status != "FAILED" and remote_node and remote_node.data_id and remote_status != "FAILED":
local_node.context["bind_data_id"] = remote_node.data_id
else:
local_node.context.pop("bind_data_id", None)
@@ -126,7 +128,9 @@ async def refresh_bind_data_id(
continue
local_node_id = remote_to_local.get(remote_node.node_id)
local_node = local_collection.get_by_node_id(local_node_id) if local_node_id else None
if local_node and local_node.data_id:
remote_status = getattr(remote_node.status, "value", None)
local_status = getattr(local_node.status, "value", None) if local_node is not None else None
if remote_status != "FAILED" and local_node and local_node.data_id and local_status != "FAILED":
remote_node.context["bind_data_id"] = local_node.data_id
else:
remote_node.context.pop("bind_data_id", None)