Skip to content

perf(classroom): GET /classrooms の DynamoDB 読み取り削減と Scan/Query のページング対応 #1146

Closed

Description

@smalruby3-editor-bot

背景

#1138 の修正で GET /classrooms の DynamoDB 呼び出しが 2 回 → 5 回になった。あわせて、
既存実装から踏襲している Scan / Query のページング未対応(LastEvaluatedKey を辿っていない)が
テーブル肥大時のサイレントな取りこぼしになる。現状はテーブルが小さい前提で成立しているが、
前提が変わる前に手を入れておく。

参照: #1139 (comment)

現状(handleListClassrooms・1 リクエストあたり)

呼び出し 対象
Query teacherSub-index 自分が作った課題(既存)
Scan contains(coTeacherEmails) 課題単位の共同管理(既存)
Query teacherSub-index(groups) 自分のクラス(新規)
Scan contains(coTeacherEmails)(groups) 共同管理クラス(新規)
Scan groupId IN (...) クラス内の課題(新規)

Classrooms テーブルのフルスキャンが 1 回 → 2 回になっている。

やること

1. 読み取り回数の削減

  • Classrooms への 2 回の Scan を contains(coTeacherEmails, :email) OR groupId IN (...) の 1 Scan に統合する。
    RCU は「フィルタ適用前に読んだ項目」に課金されるため、Scan 回数の削減がそのまま課金に効く。
  • groupId IN (...) は DynamoDB の上限(IN のオペランド 100 個)に注意。統合後もチャンク分割の考慮を残す。
  • 他にも同一リクエスト内で重複している読み取りがあれば併せて削る。

2. ページング対応(LastEvaluatedKey)

  • DynamoDB の 1MB 上限はフィルタ適用前に効くため、テーブルが 1MB を超えると
    新旧どちらの経路でも黙って打ち切られる(エラーにならないので気付けない)。
  • Scan / Query を LastEvaluatedKey が無くなるまで辿る共通ヘルパーを用意し、
    一覧系の呼び出しをそこに寄せる。無限ループ防止の上限(ページ数 or 累計件数)も入れる。
  • 特に listCoManagedGroups が見る ClassroomGroups は TTL 400 日で積み上がりやすい。

スコープ外

DoD

  • GET /classrooms の DynamoDB 呼び出し回数が削減されていることを、モック呼び出し数のテストで固定する
    (「Classrooms への Scan は 1 回まで」など)。
  • ページングのテスト: LastEvaluatedKey が返るモックで全ページ取得されることを固定する。
  • 統合後も「共同管理者が課題を見られる / 無関係な課題が混ざらない」既存テストが green(npm test 15 suites)。
  • stg にデプロイし、課題一覧が従来どおり表示されることを確認する。
  • prod へのデプロイは行わない(人間の確認事項として PR 本文に明記)。
  • 読み取り構成を変えたので docs/classroom/architecture.md の該当記述を更新する。
  • lint 0 エラー 0 警告。

autopilot-base: develop

Activity

  1. moved this to Sprint Backlog in Autopiloton Aug 29, 2026
  2. moved this from Sprint Backlog to In Progress in Autopiloton Aug 29, 2026
  3. moved this from In Progress to Review in Autopiloton Aug 29, 2026
  4. moved this from Review to In Progress in Autopiloton Aug 29, 2026
  5. moved this from In Progress to Blocked in Autopiloton Aug 29, 2026
  6. smalruby3-editor-bot commented on Aug 29, 2026

    @smalruby3-editor-bot
    Author

    🤖 autopilot: autopilot-address-review フェーズの着手時に、作業ブランチを最新の base(origin/develop)へ自動追従(merge)しようとしましたがコンフリクトしたため、安全のため merge を中断して元に戻し Blocked にしました(古い起点のまま進めると PR が大量コンフリクトになるため)。

    詳細(サニタイズ済み): Auto-merging docs/classroom/architecture.md
    Auto-merging infra/smalruby-classroom/lambda/tests/handler-archive-recovery.test.ts
    CONFLICT (content): Merge conflict in infra/smalruby-classroom/lambda/tests/handler-archive-recovery.test.ts
    Auto-merging infra/smalruby-classroom/lambda/tests/handler-co-teacher-authz.test.ts
    CONFLICT (content): Merge conflict in infra/smalruby-classroom/lambda/tests/handler-co-teacher-authz.test.ts
    Auto-merging infra/smalruby-classroom/lambda/tests/handler-group-co-teacher.test.ts
    CONFLICT (content): Merge conflict in infra/smalruby-classroom/lambda/tests/handler-gr…(切り詰め。全文はローカルログ参照)

    人間の対応: worktree で base を手動 merge / rebase してコンフリクトを解決し、🙋 HITL を外す(またはコメントする)と autopilot が再開します。

  7. moved this from Blocked to In Progress in Autopiloton Aug 29, 2026
  8. added a commit that references this issue on Aug 29, 2026
  9. 18 remaining items

  10. moved this from Review to In Progress in Autopiloton Sep 1, 2026
  11. moved this from In Progress to Review in Autopiloton Sep 1, 2026
  12. moved this from Review to In Progress in Autopiloton Sep 1, 2026
  13. moved this from In Progress to Review in Autopiloton Sep 1, 2026
  14. moved this from Review to In Progress in Autopiloton Sep 1, 2026
  15. moved this from In Progress to Review in Autopiloton Sep 1, 2026
  16. moved this from Review to In Progress in Autopiloton Sep 1, 2026
  17. added a commit that references this issue on Sep 1, 2026
  18. moved this from In Progress to No status in Autopiloton Sep 1, 2026
  19. added a commit that references this issue on Sep 29, 2026
    e172b6e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🤖 autopilotautopilot が処理対象にした Issue/PR(daemon が付与)

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions