Skip to content

fix: コンテンツ減少時の無限ページングを防止 - #117

Merged
Sinhalite merged 1 commit into
microcmsio:mainfrom
Sinhalite:codex/fix-get-all-pagination
Sep 17, 2026
Merged

Sinhalite merged 1 commit into
microcmsio:mainfrom
Sinhalite:codex/fix-get-all-pagination

Conversation

@Sinhalite

@Sinhalite Sinhalite commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

概要

  • getAllContents() と getAllContentIds() の終了条件を、取得済み件数ではなく初回の totalCount に対する offset で判定するよう変更
  • ページング中にコンテンツが削除・非公開化されても、リクエスト回数が初回件数を基準に有界になるよう修正
  • 101件→100件に減少し、2ページ目が空になるケースの回帰テストを両メソッドに追加

影響

取得中にコンテンツが増えた場合

初回の件数取得で totalCount: 101 が返り、1ページ目の取得後にコンテンツが200件へ増えた場合を例とします。

  1. limit=0 で totalCount: 101 を取得
  2. limit=100&offset=0 で100件を取得
  3. この時点でコンテンツが101件から200件へ増加
  4. limit=100&offset=100 で100件を取得
  5. offset が200となり、200 < 101 を満たさないため終了

この場合、戻り値は最大200件になります。変更前も、取得済み件数が200件となり 200 < 101 を満たさないため同じ位置で終了します。取得開始後に追加されたコンテンツをすべて追跡することは、変更前・変更後ともに保証しません。

取得中にコンテンツが減った場合

初回の件数取得で totalCount: 101 が返り、1ページ目の取得後に残りの1件が削除または非公開化された場合を例とします。

  1. limit=0 で totalCount: 101 を取得
  2. limit=100&offset=0 で100件を取得
  3. 残りの1件が削除または非公開化
  4. limit=100&offset=100 は0件を返す
  5. offset が200となり、200 < 101 を満たさないため終了

この場合、戻り値は100件になります。変更前は取得済み件数を終了条件としていたため、100 < 101 が常に成立し、offset=200, 300, ... と空ページへのリクエストが続く可能性がありました。変更後は offset=200 のリクエストを送信せず終了します。

取得中の追加・削除・並び順変更による重複や取りこぼしの可能性は従来と同じです。本変更はスナップショット一貫性を保証するものではなく、リクエスト回数を有限にするものです。

リリース予定

無限リクエストが発生する懸念があるため、本PRのマージ後、パッチバージョン v3.5.1 としてリリース予定です。

確認

  • npm test -- --runInBand
  • npm run lint
  • npm run format
  • npm run typecheck
  • npm run build

Closes #116

@coderabbitai

coderabbitai Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: fb023f16-8624-42ce-84f0-bbf8e8aa3881

📥 Commits

Reviewing files that changed from the base of the PR and between cbd80f4 and 2a45325.

📒 Files selected for processing (3)
  • src/createClient.ts
  • tests/getAllContentIds.test.ts
  • tests/getAllContents.test.ts

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


Walkthrough

getAllContentIds と getAllContents のページング継続条件を、累積取得数から offset 基準へ変更しました。ページング中に totalCount が減少した場合の停止テストを追加しました。

Changes

ページング終了条件

Layer / File(s) Summary
offset 基準のページングと回帰テスト
src/createClient.ts, tests/getAllContentIds.test.ts, tests/getAllContents.test.ts
getAllContentIds と getAllContents は、累積配列の長さではなく offset < totalCount で次のページ取得と待機を判定します。totalCount が減少した場合に、offset 100 までのリクエストで停止するテストを追加しました。

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 2a453

The pagination update bounds requests when content is removed during retrieval, and the added tests cover stopping after the empty page. No actionable merge risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed #116 の要件を満たします。src/createClient.ts の getAllContents() と getAllContentIds() は、取得済み配列の長さではなく、初回レスポンスの totalCount と offset を比較してページングを継続します。totalCount: 101 の後に100件取得し、次の空ページで offset が200になる…
Out of Scope Changes check ✅ Passed 変更は #116 に関連する2メソッドのページング終了条件と、その回帰テストだけです。無関係な実装変更は確認できません。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 3…
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed タイトルは、ページング中のコンテンツ減少による無限ページングを防止する主要な変更を正確かつ簡潔に表しています。
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@Sinhalite
Sinhalite requested a review from dc7290 September 17, 2026 00:42

@dc7290 dc7290 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

良さそうです!ありがとうございます!

@Sinhalite

Copy link
Copy Markdown
Contributor Author

@dc7290
レビューありがとうございます!
リリース進めていきます。

@Sinhalite
Sinhalite merged commit 93d68c2 into microcmsio:main Sep 17, 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.

getAllContents() が取得中のコンテンツ減少時に終了しない可能性がある

2 participants