perf(backend): 14 端点缓存+threadpool + N+1 修复 + 性能索引 + system.py 计数 - #43
Merged
Conversation
PR3 — 后端 API 性能 graph.py(14 端点补缓存 + threadpool,内联 cluster_map 模式): - overview/bridges/frontier:补 run_in_threadpool(此前 sync+cache 仍阻塞线程池槽) - cocitation-clusters O(N²) 配对:加 300s 缓存 + threadpool - citation-tree/citation-network/topic/similar-via-citation:加 60s 缓存 + threadpool - timeline/quality:加 120s 缓存 + threadpool - weekly_evolution/survey(含 LLM):加 300s 缓存 + threadpool - research-gaps(最重,2×timeline+2×LLM):加 600s 缓存 + threadpool - citation-detail/topic_deep_trace/auto_link:含外部 API 副作用,不加缓存(如实标注) N+1 修复: - papers.similar:循环 get_by_id 改 list_by_ids 一次查完 + 按 ids 顺序构建(5-20 次查询→1 次) - topics.list_topics:每主题 2 次查询改 2 次批量聚合(paper_count GROUP BY + 最近 action 按 topic 分组取首条) 性能索引迁移(alembic d4e5f6a7b8c9): - papers.publication_date 索引(list_paginated 排序/frontier 过滤/年份分组,此前全表扫) - collection_actions.created_at 索引(ORDER BY created_at DESC/每主题最近行动查询) - models.py 对应字段加 index=True 声明 - CREATE INDEX IF NOT EXISTS 幂等(PG/SQLite 通用) system.py: - 拉 200 行 ORM 仅为 len() 改 count_all() 一次 COUNT 查询
🔍 OpenCode PR Review Required这是一个受保护的分支,merge 前需要进行 code review。 请运行以下命令进行 OpenCode review: 或者在 PR 页面评论 This is an automated reminder from PR Review Gate. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PR3 — 后端 API 性能(中风险)
graph.py(14 端点补缓存 + threadpool)
N+1 修复
性能索引迁移(d4e5f6a7b8c9)
system.py
验证