disable unit caching specifically in rake tasks by davidsbailey · Pull Request #71582 · code-dot-org/code-dot-org

Follow-up from:

#71467 attempted to limit unit caching to running (puma) web servers, but this exposed an error in our existing logic in CDO.running_web_application? leading to performance issues in production.

A fix has been opened for the logic in CDO.running_web_application?, but I don't want this work to take a dependency on that work, so this PR offers a more scoped fix of just disabling caching within rake tasks.

Testing story

[10:42:13] Dave-M4:~/src/cdo/dashboard (skip-unit-cache-in-rake *)$ git diff
diff --git a/dashboard/config/environments/development.rb b/dashboard/config/environments/development.rb
-  config.cache_classes = false
-  config.cache_store = :null_store
+  config.cache_classes = true
diff --git a/dashboard/lib/services/script_seed.rb b/dashboard/lib/services/script_seed.rb
         seed_context.script = import_script(script_data, md5: md5)
+        puts "Unit.should_cache? #{Unit.should_cache?}"

[10:35:25] Dave-M4:~/src/cdo/dashboard (staging *)$ bundle exec rake seed:single_script SCRIPT_NAME=allthethings
Unit.should_cache? true
Finished seed:single_script (1 second)

[10:42:01] Dave-M4:~/src/cdo/dashboard (skip-unit-cache-in-rake *)$ bundle exec rake seed:single_script SCRIPT_NAME=allthethings
Unit.should_cache? false
Finished seed:single_script (1 second)