优化大量推送问题
This commit is contained in:
@@ -40,8 +40,6 @@ from schemas.project.project_base import (
|
||||
_PRODUCTION_PROJECT_FIELDS = [
|
||||
"plan_production_date",
|
||||
"plan_full_production_date",
|
||||
"ic_plan_first_production_date",
|
||||
"ic_plan_full_production_date",
|
||||
"actual_production_date",
|
||||
"actual_full_production_date",
|
||||
]
|
||||
@@ -185,6 +183,9 @@ class ProjectDetailApiHandler(BaseApiHandler):
|
||||
except ValidationError as e:
|
||||
results.append(TaskResult.failed(node_id=node.node_id, error=f"{ERROR_VALIDATION_FAILED}: {e}"))
|
||||
continue
|
||||
except Exception as e:
|
||||
results.append(TaskResult.failed(node_id=node.node_id, error=str(e)))
|
||||
continue
|
||||
|
||||
push_id = self._generate_push_id()
|
||||
biz_id = project_id
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from ...common.sync_node import SyncNode
|
||||
@@ -36,6 +38,12 @@ class ProjectDetailSyncStrategy(DefaultSyncStrategy[ProjectDetailProject]):
|
||||
"climb_production",
|
||||
"challenge_production",
|
||||
}
|
||||
_PRODUCTION_PROJECT_FIELDS = (
|
||||
"plan_production_date",
|
||||
"plan_full_production_date",
|
||||
"actual_production_date",
|
||||
"actual_full_production_date",
|
||||
)
|
||||
|
||||
default_config = StrategyConfig(
|
||||
auto_bind=True,
|
||||
@@ -153,6 +161,11 @@ class ProjectDetailSyncStrategy(DefaultSyncStrategy[ProjectDetailProject]):
|
||||
def domain_option(self) -> ProjectDetailDomainOption:
|
||||
return ProjectDetailDomainOption.model_validate(self.config.domain_option)
|
||||
|
||||
async def create_for_direction(self, *, source_is_local: bool) -> list[SyncNode]:
|
||||
created_nodes = await super().create_for_direction(source_is_local=source_is_local)
|
||||
await self._enrich_created_production_nodes(created_nodes, source_is_local=source_is_local)
|
||||
return created_nodes
|
||||
|
||||
def normalize_compare_payload(self, data: dict | None, data_id_map=None) -> dict:
|
||||
normalized = super().normalize_compare_payload(data, data_id_map)
|
||||
key = normalized.get("key")
|
||||
@@ -223,3 +236,48 @@ class ProjectDetailSyncStrategy(DefaultSyncStrategy[ProjectDetailProject]):
|
||||
return key
|
||||
return None
|
||||
|
||||
async def _enrich_created_production_nodes(self, created_nodes: list[SyncNode], *, source_is_local: bool) -> None:
|
||||
if not created_nodes:
|
||||
return
|
||||
|
||||
source_collection = self.local_collection if source_is_local else self.remote_collection
|
||||
|
||||
for created_node in created_nodes:
|
||||
created_data = created_node.get_data() or {}
|
||||
if self._extract_node_key(created_node) != "production":
|
||||
continue
|
||||
|
||||
if all(created_data.get(field) not in (None, "") for field in self._PRODUCTION_PROJECT_FIELDS):
|
||||
continue
|
||||
|
||||
if source_is_local:
|
||||
source_node_id = await self.binding_manager.get_local_id(self.node_type, created_node.node_id)
|
||||
else:
|
||||
source_node_id = await self.binding_manager.get_remote_id(self.node_type, created_node.node_id)
|
||||
if not source_node_id:
|
||||
continue
|
||||
|
||||
source_node = source_collection.get(source_node_id)
|
||||
if source_node is None:
|
||||
continue
|
||||
|
||||
source_data = source_node.get_data() or {}
|
||||
project_id = source_data.get("project_id")
|
||||
if not project_id:
|
||||
continue
|
||||
|
||||
project_node = source_collection.get_by_data_id("project", str(project_id))
|
||||
if project_node is None:
|
||||
continue
|
||||
|
||||
project_data = project_node.get_data() or {}
|
||||
updated_data: dict[str, Any] = dict(created_data)
|
||||
changed = False
|
||||
for field in self._PRODUCTION_PROJECT_FIELDS:
|
||||
if updated_data.get(field) in (None, "") and project_data.get(field) not in (None, ""):
|
||||
updated_data[field] = project_data.get(field)
|
||||
changed = True
|
||||
|
||||
if changed:
|
||||
created_node.set_data(updated_data)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user