feat(items): 未来日時のItemを一覧に表示しない#751
Conversation
遠い未来の published_at が設定された Item が /items の先頭に 並んでしまうため、現在から1ヶ月後より未来のものを表示対象から除外する。 新しい順の表示順は維持。
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! このプルリクエストは、アイテム一覧ページにおいて遠い未来の日時を持つアイテムが上位に表示されてしまう問題を修正するものです。公開日時が1ヶ月以内のアイテムのみを抽出するようにクエリを制限し、表示の整合性を向上させました。 Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. 未来の日時 一覧から消え 今が見える コードの工夫 静かなる修正 Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request limits the items displayed in the index action to those published within one month from now and adds integration tests to verify this behavior. The review feedback suggests refactoring the query logic into a reusable scope within the Item model to keep the controller clean.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| def index | ||
| page = (params[:page].presence || 1).to_i | ||
| @items = Item.preload(:pawprints).eager_load(:channel).order(published_at: :desc, title: :desc).page(page).per(48) | ||
| @items = Item.where("published_at <= ?", 1.month.from_now).preload(:pawprints).eager_load(:channel).order(published_at: :desc, title: :desc).page(page).per(48) |
There was a problem hiding this comment.
コントローラー内に直接 where("published_at <= ?", 1.month.from_now) というクエリロジックを記述するのではなく、Item モデルにスコープ(scope)として定義することを推奨します。これにより、コントローラーがシンプルに保たれ、将来的に他の場所で同様のフィルタリングを行う際にも再利用しやすくなります。
モデル側への実装例:
# app/models/item.rb
scope :published_before, ->(time) { where("published_at <= ?", time) } @items = Item.published_before(1.month.from_now).preload(:pawprints).eager_load(:channel).order(published_at: :desc, title: :desc).page(page).per(48)レビュー指摘を受けて、コントローラ直書きのクエリを Item.published_before scope に整理。挙動は変えない。
1ヶ月の猶予を持たせる方針から、現在時刻より未来のものは すべて表示しない方針に変更。割り切ってシンプルにする。
Summary
/itemsに未来のpublished_atを持つ Item が先頭に並んでしまう問題に対処Item.published_before(Time.current)で、現在時刻より未来の Item は表示しない (割り切り)order(published_at: :desc, title: :desc)) はそのまま維持Item.published_before(time)scope に切り出し済み (レビュー反映)channels#show等の他の表示箇所は今回は対象外 (意図的にそのまま)Test plan
test/integration/items_test.rbを追加 (TDD)rails test test/integration/items_test.rbが greenrubocopオフェンスなし