优化性能

This commit is contained in:
strepsiades
2026-04-01 18:13:18 +08:00
parent 9a3a34c58b
commit f93a6c5c68
8 changed files with 198 additions and 107 deletions
@@ -308,51 +308,13 @@ class ProjectDetailApiHandler(BaseApiHandler):
def _create_node(self, data: Dict[str, Any]) -> SyncNode:
project_id_raw = data.get("project_id")
key_raw = self._normalize_key(data.get("key"))
project_id = str(project_id_raw) if project_id_raw else ""
key = str(key_raw) if key_raw else ""
loaded_data_id = str(data.get("id") or data.get("_id") or "")
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:
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:
node.context["project_id"] = project_id
return node
def _find_existing_by_project_key(self, *, project_id: str, key: str) -> Optional[SyncNode]:
if not project_id or not key or self._collection is None:
return None
candidates = self._collection.filter(
node_type=self.node_type,
node_filter=lambda n: (
((n.get_data() or {}).get("project_id") == project_id)
and (self._normalize_key((n.get_data() or {}).get("key")) == key)
),
)
if not candidates:
return None
if len(candidates) > 1:
raise RuntimeError(
f"Duplicate project_detail_data detected: project_id={project_id}, key={key}, count={len(candidates)}"
)
return candidates[0]
async def _get_project_all_info(self, project_id: str, *, force_refresh: bool = False) -> Dict[str, Any]:
from ..project.api_handler import ProjectApiHandler