Skip to content

Commit

Permalink
Merge pull request #379 from openstax/search_digest
Browse files Browse the repository at this point in the history
Calculate a search digest from the search results
  • Loading branch information
Dantemss authored Sep 7, 2022
2 parents 0876f91 + f5ffb8d commit d5d5048
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
17 changes: 8 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ GEM
pager (~> 1.0)
choice (0.2.0)
chronic (0.10.2)
codecov (0.2.12)
json
simplecov
codecov (0.6.0)
simplecov (>= 0.15, < 0.22)
concurrent-ruby (1.1.9)
crack (0.4.5)
rexml
Expand All @@ -149,9 +148,9 @@ GEM
ejs (1.1.1)
erubi (1.10.0)
eventmachine (1.2.7)
exception_notification (4.4.3)
actionmailer (>= 4.0, < 7)
activesupport (>= 4.0, < 7)
exception_notification (4.5.0)
actionmailer (>= 5.2, < 8)
activesupport (>= 5.2, < 8)
excon (0.79.0)
execjs (2.7.0)
factory_bot (6.1.0)
Expand Down Expand Up @@ -231,7 +230,6 @@ GEM
thor (>= 0.14, < 2.0)
jquery-ui-rails (6.0.1)
railties (>= 3.2.16)
json (2.5.1)
jwt (2.3.0)
keyword_search (1.5.0)
lev (11.0.0)
Expand Down Expand Up @@ -311,7 +309,8 @@ GEM
rails (>= 5.0, < 7.0)
representable
roar (>= 1.0)
openstax_api (9.4.1)
openstax_api (9.5.0)
addressable
doorkeeper
exception_notification
lev (>= 11)
Expand Down Expand Up @@ -484,7 +483,7 @@ GEM
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.3)
simplecov_json_formatter (0.1.4)
sortability (1.0.0)
rails
sprockets (3.7.2)
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/api/v1/exercises_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ def index

standard_search(
Exercise, SearchExercises, Exercises::SearchRepresenter, user: current_api_user
)
) do |outputs|
digest = Digest::SHA256.new
outputs.items.each { |exercise| digest << exercise.cache_key_with_version }
response.headers['X-Digest'] = digest.hexdigest
end
end

##########
Expand Down
6 changes: 6 additions & 0 deletions config/initializers/cache.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Clear the Rails cache on code reload (dev environment only)
if Rails.env.development? && !Rails.application.config.cache_classes
Rails.autoloaders.main.on_unload do |klass, _abspath|
Rails.cache.clear
end
end

0 comments on commit d5d5048

Please sign in to comment.