Skip to content

Commit

Permalink
Move search index name to a central config location.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinemde committed Dec 4, 2024
1 parent e68889c commit 2dd1d6e
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/models/gem_download.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def downloads_by_gem(rubygem_ids)
end

def update_query(id, downloads, version_downloads)
{ update: { _index: "rubygems-#{Rails.env}",
{ update: { _index: Gemcutter::SEARCH_INDEX_NAME,
_id: id,
data: { doc: { downloads: downloads, version_downloads: version_downloads } } } }
end
Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def self.config
POPULAR_DAYS_LIMIT = 70.days
PROTOCOL = config["protocol"]
REMEMBER_FOR = 2.weeks
SEARCH_INDEX_NAME = "rubygems-#{Rails.env}".freeze
SEARCH_INDEX_NAME = ENV.fetch("SEARCH_INDEX_NAME", "rubygems-#{Rails.env}".freeze)
SEARCH_NUM_REPLICAS = ENV.fetch("SEARCH_NUM_REPLICAS", 1).to_i
SEARCH_MAX_PAGES = 100 # Limit max page as ES result window is upper bounded by 10_000 records
STATS_MAX_PAGES = 10
Expand Down
2 changes: 2 additions & 0 deletions config/deploy/web.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ spec:
key: elasticsearch_url
- name: SEARCH_NUM_REPLICAS
value: "<%= environment == 'production' ? 2 : 1 %>"
- name: SEARCH_INDEX_NAME
value: "rubygems-<%= environment %>"
- name: MEMCACHED_ENDPOINT
valueFrom:
secretKeyRef:
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/es_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ def es_version_downloads(id)

def get_response(id)
Rubygem.searchkick_index.refresh
Searchkick.client.get index: "rubygems-#{Rails.env}", id: id
Searchkick.client.get index: Gemcutter::SEARCH_INDEX_NAME, id: id
end
end
3 changes: 1 addition & 2 deletions test/models/deletion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ class DeletionTest < ActiveSupport::TestCase

perform_enqueued_jobs

response = Searchkick.client.get index: "rubygems-#{Rails.env}",
id: @version.rubygem_id
response = Searchkick.client.get index: Gemcutter::SEARCH_INDEX_NAME, id: @version.rubygem_id

assert response["_source"]["yanked"]
end
Expand Down
6 changes: 2 additions & 4 deletions test/models/pusher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,7 @@ def two_cert_chain(signing_key:, root_not_before: Time.current, cert_not_before:
should "create rubygem index" do
@rubygem.update_column("updated_at", Date.new(2016, 07, 04))
perform_enqueued_jobs only: ReindexRubygemJob
response = Searchkick.client.get index: "rubygems-#{Rails.env}",
id: @rubygem.id
response = Searchkick.client.get index: Gemcutter::SEARCH_INDEX_NAME, id: @rubygem.id
expected_response = {
"name" => "gemsgemsgems",
"downloads" => 0,
Expand Down Expand Up @@ -733,8 +732,7 @@ def two_cert_chain(signing_key:, root_not_before: Time.current, cert_not_before:

should "update rubygem index" do
perform_enqueued_jobs only: ReindexRubygemJob
response = Searchkick.client.get index: "rubygems-#{Rails.env}",
id: @rubygem.id
response = Searchkick.client.get index: Gemcutter::SEARCH_INDEX_NAME, id: @rubygem.id

assert_equal "new summary", response["_source"]["summary"]
end
Expand Down

0 comments on commit 2dd1d6e

Please sign in to comment.