From be39cf1bab9b9d3f089ab2d029110f9004c557c5 Mon Sep 17 00:00:00 2001 From: Dante Soares Date: Wed, 7 Sep 2022 11:32:51 -0500 Subject: [PATCH 1/2] Calculate a search digest from the search results --- Gemfile.lock | 9 +++++---- app/controllers/api/v1/exercises_controller.rb | 6 +++++- config/initializers/cache.rb | 6 ++++++ 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 config/initializers/cache.rb diff --git a/Gemfile.lock b/Gemfile.lock index 5b07c66e..7e1f0664 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -149,9 +149,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) @@ -311,7 +311,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) diff --git a/app/controllers/api/v1/exercises_controller.rb b/app/controllers/api/v1/exercises_controller.rb index 51feda7d..203ce4d2 100644 --- a/app/controllers/api/v1/exercises_controller.rb +++ b/app/controllers/api/v1/exercises_controller.rb @@ -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 ########## diff --git a/config/initializers/cache.rb b/config/initializers/cache.rb new file mode 100644 index 00000000..c7ec8812 --- /dev/null +++ b/config/initializers/cache.rb @@ -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 From f5ffb8db9ca120038748c53218b0656bae619c4e Mon Sep 17 00:00:00 2001 From: Dante Soares Date: Wed, 7 Sep 2022 15:46:42 -0500 Subject: [PATCH 2/2] Updated codecov to fix failure --- Gemfile.lock | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 7e1f0664..7b123a4e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 @@ -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) @@ -485,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)