Skip to content

fix: crawl の shouldStop 境界条件を修正し毎時の無駄な再フェッチを解消#276

Merged
coji merged 3 commits intomainfrom
fix/crawl-refetch-off-by-one
Apr 6, 2026
Merged

fix: crawl の shouldStop 境界条件を修正し毎時の無駄な再フェッチを解消#276
coji merged 3 commits intomainfrom
fix/crawl-refetch-off-by-one

Conversation

@coji
Copy link
Copy Markdown
Owner

@coji coji commented Apr 6, 2026

Summary

  • pullrequestListshouldStop 比較が < (strictly less than) だったため、updatedAt == lastFetchedAt の PR が毎回フィルタを通過し、全 repo の最新 PR が毎時再フェッチされていた
  • <= に修正して既にフェッチ済みの PR を除外
  • paginateGraphQL の shouldStop 境界条件のテストを追加

Background

本番 DB を調査したところ、深夜・休日など稼働がない時間帯でも全 org で毎時一定数の PR が更新されていた。原因は各 repo の最新 PR(updatedAt == MAX(github_raw_data.updated_at))が off-by-one で毎回再フェッチされていたため。repo 数 × 6 API calls/PR の無駄が毎時発生していた。

Test plan

  • paginateGraphQL の shouldStop テスト追加(updatedAt == stopBefore で除外されること)
  • pnpm vitest run batch/github/fetcher.test.ts 全パス
  • pnpm typecheck && pnpm build && pnpm test 全パス
  • デプロイ後、durably の crawl output で pullCount: 0 が出ることを確認

🤖 Generated with Claude Code

Summary by CodeRabbit

リリースノート

  • バグ修正

    • ページネーション処理で、更新日時が同じ場合の境界条件(等しい場合の停止)を改善しました。
  • テスト

    • ページネーションの停止条件とフィルタリング動作を検証する新しいテストスイートを追加しました。

pullrequestList の shouldStop が `<` (strictly less than) だったため、
updatedAt == lastFetchedAt の PR が毎回フィルタを通過し、全 repo の最新 PR が
毎時再フェッチされていた。`<=` に修正して既にフェッチ済みの PR を除外する。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 6, 2026

Warning

Rate limit exceeded

@coji has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 21 minutes and 8 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 21 minutes and 8 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5e1baf4c-7d21-46f4-914c-037533f2f834

📥 Commits

Reviewing files that changed from the base of the PR and between aee95d4 and 7d72c26.

📒 Files selected for processing (1)
  • batch/github/fetcher.test.ts
📝 Walkthrough

Walkthrough

GraphQL ページネーション補助関数 paginateGraphQL をモジュール外公開し、PR 取得の早期停止条件を node.updatedAt < stopBefore から node.updatedAt <= stopBefore に変更。これを検証するテスト群を追加しました。

Changes

Cohort / File(s) Summary
テスト追加
batch/github/fetcher.test.ts
paginateGraphQL をインポートして新しい describe('paginateGraphQL shouldStop'...) テスト群を追加。shouldStop の有無/挙動に応じたページネーション停止ロジックを検証する非同期ケースを追加。
API エクスポートと停止条件の更新
batch/github/fetcher.ts
内部関数 paginateGraphQLexport 化して公開 API とし、pullrequestList(stopBefore?) の停止判定を node.updatedAt < stopBefore から node.updatedAt <= stopBefore に変更。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 分

Possibly related issues

Possibly related PRs

🐰 新しい道を渡る小さな足音、
paginateGraphQL はひょいと跳ねる、
停止の合図は「以下」で止まるよ、
テストの光が夜を照らし、
すべてのPRが整列するよ。

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PRタイトルは、shouldStop境界条件の修正とそれによる毎時の無駄な再フェッチ解消という、変更の主要な目的と技術的内容を正確に反映しており、PR目的セクションの説明と整合している。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/crawl-refetch-off-by-one

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coji and others added 2 commits April 6, 2026 12:07
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coji coji merged commit b00d206 into main Apr 6, 2026
4 checks passed
@coji coji deleted the fix/crawl-refetch-off-by-one branch April 6, 2026 03:09
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.

1 participant