-
Notifications
You must be signed in to change notification settings - Fork 1
perf(pipeline): LLM timeout+concurrency, bulk AI persist, off-loop parse, batched events [修复组⑤] #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |||||||||||||||||||||||||||||||||
| from email.utils import parsedate_to_datetime | ||||||||||||||||||||||||||||||||||
| from typing import Any | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| from sqlalchemy import select | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| from backend.channels.base import ChannelFetchError | ||||||||||||||||||||||||||||||||||
| from backend.control.error_kinds import map_error_type, map_exception | ||||||||||||||||||||||||||||||||||
| from backend.control.recorder import FreshnessInfo, record_run_measurement | ||||||||||||||||||||||||||||||||||
|
|
@@ -400,16 +402,28 @@ async def run_pipeline( | |||||||||||||||||||||||||||||||||
| # in backend.pipeline.runner phase 2, so it's used as-is. | ||||||||||||||||||||||||||||||||||
| resolve_provider=agent_config is None, | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| # Persist enrichments — new_records are detached after step3 session closed | ||||||||||||||||||||||||||||||||||
| # Persist enrichments — new_records are detached after step3 session | ||||||||||||||||||||||||||||||||||
| # closed. AUDIT C21: one bulk SELECT ... WHERE id IN (...) + an | ||||||||||||||||||||||||||||||||||
| # in-memory id->row map, instead of one `session.get` per record | ||||||||||||||||||||||||||||||||||
| # (N+1) — same field writes (ai_enrichment, status="ai_processed"). | ||||||||||||||||||||||||||||||||||
| from backend.models.record import CollectedRecord | ||||||||||||||||||||||||||||||||||
| async with AsyncSessionLocal() as session: | ||||||||||||||||||||||||||||||||||
| for rec in new_records: | ||||||||||||||||||||||||||||||||||
| if rec.ai_enrichment is not None: | ||||||||||||||||||||||||||||||||||
| db_rec = await session.get(CollectedRecord, rec.id) | ||||||||||||||||||||||||||||||||||
| enriched_ids = [rec.id for rec in new_records if rec.ai_enrichment is not None] | ||||||||||||||||||||||||||||||||||
| if enriched_ids: | ||||||||||||||||||||||||||||||||||
| async with AsyncSessionLocal() as session: | ||||||||||||||||||||||||||||||||||
| db_recs = ( | ||||||||||||||||||||||||||||||||||
| await session.execute( | ||||||||||||||||||||||||||||||||||
| select(CollectedRecord).where(CollectedRecord.id.in_(enriched_ids)) | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| ).scalars().all() | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+411
to
+417
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 在 SQLite 中,单个 SQL 查询中的参数(变量)数量默认限制为 999 个。如果 为了提高代码的健壮性,建议对
Suggested change
|
||||||||||||||||||||||||||||||||||
| db_recs_by_id = {db_rec.id: db_rec for db_rec in db_recs} | ||||||||||||||||||||||||||||||||||
| for rec in new_records: | ||||||||||||||||||||||||||||||||||
| if rec.ai_enrichment is None: | ||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||
| db_rec = db_recs_by_id.get(rec.id) | ||||||||||||||||||||||||||||||||||
| if db_rec: | ||||||||||||||||||||||||||||||||||
| db_rec.ai_enrichment = rec.ai_enrichment | ||||||||||||||||||||||||||||||||||
| db_rec.status = "ai_processed" | ||||||||||||||||||||||||||||||||||
| await session.commit() | ||||||||||||||||||||||||||||||||||
| await session.commit() | ||||||||||||||||||||||||||||||||||
| logger.info("[task:%s] step4/ai done | processed=%d", task_id, ai_count) | ||||||||||||||||||||||||||||||||||
| if run_id: | ||||||||||||||||||||||||||||||||||
| # AUDIT C3: ai_count is now the real enrichment count (0 when | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在
emit_many批量写入事件时,直接使用event["step"]和event["message"]进行字典取值。如果传入的事件列表中有任何一个事件字典缺失了"step"或"message"键,将会抛出KeyError异常。虽然整个操作被包裹在
try...except块中,但一个事件的格式错误会导致整批事件全部写入失败。建议使用.get()方法并提供合理的默认值,以提高公共工具函数的容错性和健壮性。