Skip to content

⚡ perf: avoid timeline bootstrap for lightweight PR views#30

Merged
SigureMo merged 1 commit intoShigureLab:mainfrom
ShigureNyako:fix/pr-view-lite-show-mode
Mar 21, 2026
Merged

⚡ perf: avoid timeline bootstrap for lightweight PR views#30
SigureMo merged 1 commit intoShigureLab:mainfrom
ShigureNyako:fix/pr-view-lite-show-mode

Conversation

@ShigureNyako
Copy link
Copy Markdown
Member

Motivation

Closes #25.

gh-llm pr view --show meta and other lightweight --show combinations were still bootstrapping the timeline before deciding what to render. That made metadata-only and checks-only views pay the heavier timeline GraphQL cost and widened the failure surface for commands that should stay lightweight.

What changed

  • added a reusable build_context_from_meta() helper so PR metadata can be rendered without timeline bootstrap
  • updated pr view to load timeline pages only when --show actually includes timeline
  • updated pr checks to render from metadata context directly instead of building timeline state first
  • hid timeline_events / page_size / total_pages from frontmatter when timeline was not loaded, so lightweight output does not pretend those values were fetched
  • added regression coverage for --show meta, --show checks, --show mergeability, and pr checks

Validation

  • uv run pytest
  • uv run ruff check .
  • uv run pyright src/gh_llm tests
  • uv run gh-llm pr view 77938 --repo PaddlePaddle/Paddle --show meta
  • uv run gh-llm pr view 77938 --repo PaddlePaddle/Paddle --show checks
  • uv run gh-llm pr checks --pr 77938 --repo PaddlePaddle/Paddle

@SigureMo Please review this PR when you have time. Thanks!

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

checks = client.fetch_checks(meta.ref) if meta.state == "OPEN" else []

P2 Badge Fetch status checks even for closed PR mergeability views

For a closed-but-unmerged PR, this branch now forces checks=[], but render_mergeability_section() still relies on the check list to add blockers for required failing or pending status checks (src/gh_llm/render.py:262-278). As a result, pr view --show mergeability can flip from “blocked” to “allowed” whenever the only blocker is a required check, which is misleading for PRs that can still be reopened and merged.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes gh-llm pr view / gh-llm pr checks truly “lightweight” when timeline output isn’t requested, avoiding the heavier timeline GraphQL bootstrap and reducing failure surface for metadata/checks-only views.

Changes:

  • Introduces build_context_from_meta() to construct a renderable PR context from metadata without loading timeline pages.
  • Updates pr view to only bootstrap timeline pages when --show includes timeline, and updates pr checks to render from metadata context directly.
  • Adjusts frontmatter rendering to omit timeline_events / page_size / total_pages unless timeline data was actually loaded, and adds regression tests for these lightweight paths.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/test_cli.py Adds regression tests ensuring meta/checks/mergeability views and pr checks don’t trigger timeline GraphQL queries.
src/gh_llm/render.py Hides timeline pagination/count fields in frontmatter unless timeline_loaded is true.
src/gh_llm/pager.py Adds build_context_from_meta() and reuses it from build_initial() to avoid duplicated context construction.
src/gh_llm/models.py Adds timeline_loaded to TimelineContext and ensures it round-trips via to_dict/from_dict.
src/gh_llm/commands/pr.py Skips timeline bootstrap in pr view unless requested; makes pr checks build context from metadata and avoid timeline work.
Comments suppressed due to low confidence (1)

src/gh_llm/commands/pr.py:583

  • cmd_pr_checks (and pr view --show checks) currently treat any non-OPEN PR as having no checks: it skips fetch_checks and passes is_open=False into render_checks_section. However render_checks_section’s message for closed PRs explicitly tells users to rerun pr checks ... --all, which will still not show checks with the current is_open logic. Consider either (a) allowing --all to fetch and render checks for closed/merged PRs (e.g., treat is_open as meta.state == 'OPEN' or args.all), or (b) updating the closed-PR message/behavior so --all isn’t suggested when it can’t change the output.
    meta = _resolve_pr_meta(client=client, args=args)
    context = build_context_from_meta(meta=meta, page_size=DEFAULT_PAGE_SIZE)
    checks = client.fetch_checks(meta.ref) if meta.state == "OPEN" else []
    for line in render_checks_section(
        context=context,
        checks=checks,
        show_all=bool(args.all),
        is_open=(meta.state == "OPEN"),
    ):

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Member Author

@ShigureNyako ShigureNyako left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

结论:APPROVE

我本地复跑了 uv run ruff checkuv run pyrightuv run pytest -q,并实际验证了这几个命令:

  • uv run gh-llm pr view 30 --repo ShigureLab/gh-llm --show meta
  • uv run gh-llm pr checks --pr 30 --repo ShigureLab/gh-llm --all
  • uv run gh-llm pr view 30 --repo ShigureLab/gh-llm --show mergeability

这版改动把轻量视图和 timeline bootstrap 解耦得比较干净:

  • build_context_from_meta() 的抽取让 meta/checks/mergeability 这些只依赖 PR 元信息的路径不再强绑 timeline
  • render_frontmatter() 只在 timeline 实际加载后再输出 timeline_events/page_size/total_pages,语义更准确
  • 回归测试也覆盖了 --show meta / --show checks / --show mergeability / pr checks 这几个关键轻量路径

我这里没有看到新的阻塞性问题,可以合。

@SigureMo SigureMo merged commit 4d717d2 into ShigureLab:main Mar 21, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pr view --show meta 等轻量查看不应无条件拉取 timeline 首尾页

3 participants