From 3a0630fb191a7bc30471d0c94faeff0f3925c078 Mon Sep 17 00:00:00 2001 From: Albert Chae Date: Fri, 16 Feb 2024 22:18:57 -0800 Subject: [PATCH] Fetch oldest authored_at correctly instead of oldest authored_at per page Fixes https://github.com/rubygems/rubygems.org/issues/4448 Previously, the "since date" was using oldest `version.authored_at` for a given page. This change fixes it to get the oldest `version.authored_at` in the database. Because `authored_at` depends on either `built_at` or `created_at`, I fetch both and take the min. This should only be 2 additional queries of 1 record each. I modified existing tests to check for the "versions since" text and also have 2 pages of actual content. --- app/controllers/versions_controller.rb | 9 ++++++ app/views/versions/index.html.erb | 2 +- test/functional/versions_controller_test.rb | 34 +++++++++++++-------- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb index e5bdfe34f84..057d3f7ebf6 100644 --- a/app/controllers/versions_controller.rb +++ b/app/controllers/versions_controller.rb @@ -3,6 +3,7 @@ class VersionsController < ApplicationController def index set_page + set_oldest_version_date @versions = @rubygem.versions.by_position.page(@page).per(Gemcutter::VERSIONS_PER_PAGE) end @@ -14,4 +15,12 @@ def show @on_version_page = true render "rubygems/show" end + + private + + def set_oldest_version_date + oldest_created_at = @rubygem.versions.order(:created_at).first + oldest_built_at = @rubygem.versions.order(:built_at).first + @oldest_version_date = [oldest_created_at, oldest_built_at].compact.map(&:authored_at).min + end end diff --git a/app/views/versions/index.html.erb b/app/views/versions/index.html.erb index 94620b1f37d..3a8a919d373 100644 --- a/app/views/versions/index.html.erb +++ b/app/views/versions/index.html.erb @@ -4,7 +4,7 @@

<%= t('.not_hosted_notice') %>

<% else %> -

<%= t('.versions_since', :count => @versions.total_count, :since => nice_date_for(@versions.map(&:authored_at).min)) %>:

+

<%= t('.versions_since', :count => @versions.total_count, :since => nice_date_for(@oldest_version_date)) %>: