(
user_id: str = "",
query: str = "",
days: int = 30,
limit: int = 80,
exact_date: str = "",
)
| 2897 | # PAPERFLOW_MAX_CONCURRENCY,默认 3)同时精读多篇论文,而不是一篇一篇地串行处理。 |
| 2898 | result_docs: List[Dict[str, Any]] = [] |
| 2899 | batch_error: Optional[str] = None |
| 2900 | try: |
| 2901 | result = create_reading_reports( |
| 2902 | user_id=user_id, |
| 2903 | push_id=push_id, |
| 2904 | paper_numbers=selected_numbers, |
| 2905 | write_feishu=write_feishu, |
| 2906 | response_language=response_language, |
| 2907 | ) |
| 2908 | result_docs = list(result.get("created_docs") or []) |
| 2909 | except Exception as exc: |
| 2910 | batch_error = str(exc) |
| 2911 | |
| 2912 | # 3) 把批量结果回填到每篇论文对应的占位槽(优先按 report_id 匹配,其余按顺序兜底)。 |
| 2913 | results_by_report_id: Dict[str, Dict[str, Any]] = {} |
| 2914 | leftover_results: List[Dict[str, Any]] = [] |
| 2915 | for result_doc in result_docs: |
| 2916 | report_id = str(result_doc.get("report_id") or "").strip() |
| 2917 | if report_id and report_id not in results_by_report_id: |
| 2918 | results_by_report_id[report_id] = result_doc |
| 2919 | else: |
| 2920 | leftover_results.append(result_doc) |
| 2921 | |
| 2922 | for index, number in enumerate(selected_numbers): |
| 2923 | doc = docs[index] if index < len(docs) else {} |
| 2924 | paper = doc.get("paper_raw") or doc.get("paper") or {} |
| 2925 | report_path = Path(str(doc.get("report_path") or "")) |
| 2926 | expected_report_id = "" |
| 2927 | if index < len(created_docs_snapshot): |
| 2928 | expected_report_id = str((created_docs_snapshot[index] or {}).get("report_id") or "").strip() |
| 2929 | |
| 2930 | matched: Optional[Dict[str, Any]] = None |
| 2931 | if expected_report_id and expected_report_id in results_by_report_id: |
| 2932 | matched = results_by_report_id.pop(expected_report_id) |
| 2933 | elif leftover_results: |
| 2934 | matched = leftover_results.pop(0) |
| 2935 | |
| 2936 | if matched: |
| 2937 | completed_docs.append(matched) |
| 2938 | with _READING_TASK_LOCK: |
| 2939 | task = _READING_TASKS.get(task_id) |
| 2940 | if task: |
| 2941 | task["completed_count"] = int(task.get("completed_count") or 0) + 1 |
| 2942 | if index < len(task.get("created_docs") or []): |
| 2943 | task["created_docs"][index] = matched |
| 2944 | task["updated_at"] = _task_timestamp() |
| 2945 | else: |
| 2946 | error = batch_error or "reading report generation failed" |
no test coverage detected