From 330c14f6e85fbf9f20143f5afd45ae2d7219e76f Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Wed, 21 Feb 2024 09:52:55 -0800 Subject: [PATCH] Only include indexed rubygems in /names (#4475) --- app/models/gem_info.rb | 2 +- test/integration/api/compact_index_test.rb | 4 ++-- test/models/gem_info_test.rb | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/models/gem_info.rb b/app/models/gem_info.rb index 1a939679cc6..629722c02e5 100644 --- a/app/models/gem_info.rb +++ b/app/models/gem_info.rb @@ -26,7 +26,7 @@ def self.ordered_names(cached: true) StatsD.increment "compact_index.memcached.names.hit" else StatsD.increment "compact_index.memcached.names.miss" - names = Rubygem.order("name").pluck("name") + names = Rubygem.with_versions.order("name").pluck("name") Rails.cache.write("names", names) end names diff --git a/test/integration/api/compact_index_test.rb b/test/integration/api/compact_index_test.rb index cc86fe99874..1e812bc19d6 100644 --- a/test/integration/api/compact_index_test.rb +++ b/test/integration/api/compact_index_test.rb @@ -16,8 +16,8 @@ def digest(body) # another gem rubygem = create(:rubygem, name: "gemA") - dep1 = create(:rubygem, name: "gemA1") - dep2 = create(:rubygem, name: "gemA2") + dep1 = create(:rubygem, name: "gemA1", indexed: true) + dep2 = create(:rubygem, name: "gemA2", indexed: true) # minimal version create(:version, diff --git a/test/models/gem_info_test.rb b/test/models/gem_info_test.rb index 75812fa8f15..0e2196dbc0c 100644 --- a/test/models/gem_info_test.rb +++ b/test/models/gem_info_test.rb @@ -46,7 +46,9 @@ class GemInfoTest < ActiveSupport::TestCase context ".ordered_names" do setup do - %w[abc bcd abd].each { |name| create(:rubygem, name: name) } + %w[abc bcd abd].each { |name| create(:rubygem, name:, indexed: true) } + + create(:rubygem, name: "abe", indexed: false) @ordered_names = %w[abc abd bcd] end