Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

Commit

Permalink
⚡ Add index to items slug and cache some queries
Browse files Browse the repository at this point in the history
  • Loading branch information
stephannv committed Feb 21, 2022
1 parent d4340ec commit 091ce42
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 6 deletions.
4 changes: 3 additions & 1 deletion app/actions/items/list_genres.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ class ListGenres < Actor
output :genres, type: Array

def call
self.genres = Item.pluck(:genres).flatten.uniq.sort
self.genres = Rails.cache.fetch('cache-genres', expires_in: 8.hours) do
Item.pluck(:genres).flatten.uniq.sort
end
end
end
end
4 changes: 3 additions & 1 deletion app/actions/items/list_languages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ class ListLanguages < Actor
output :languages, type: Array

def call
self.languages = Item.pluck(:languages).flatten.uniq.compact.sort
self.languages = Rails.cache.fetch('cache-languages', expires_in: 8.hours) do
Item.pluck(:languages).flatten.uniq.compact.sort
end
end
end
end
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
config.action_controller.perform_caching = true
config.action_controller.enable_fragment_cache_logging = true

config.cache_store = :memory_store
config.cache_store = :file_store, Rails.root.join('tmp/cache')
config.public_file_server.headers = {
'Cache-Control' => "public, max-age=#{2.days.to_i}"
}
Expand Down
2 changes: 1 addition & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
config.log_tags = [:request_id]

# Use a different cache store in production.
# config.cache_store = :mem_cache_store
config.cache_store = :file_store, Rails.root.join('tmp/cache')

# Use a real queuing backend for Active Job (and separate queues per environment).
# config.active_job.queue_adapter = :resque
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/sentry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
# Set tracesSampleRate to 1.0 to capture 100%
# of transactions for performance monitoring.
# We recommend adjusting this value in production
config.traces_sample_rate = 0.5
config.traces_sample_rate = 0.2
end
end
5 changes: 5 additions & 0 deletions db/migrate/20220214140037_add_index_to_items_slug.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddIndexToItemsSlug < ActiveRecord::Migration[7.0]
def change
add_index :items, :slug
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 091ce42

Please sign in to comment.