diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2016-12-03 18:21:26 +0100 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2016-12-03 18:21:26 +0100 |
commit | 816284d73924ceb453c76d571bcb315be91b2b08 (patch) | |
tree | 2fbf97bed916b582600e333c591d74c40f308111 /app/controllers | |
parent | 253970cb736a4da29229b930a0af32ead7e5d99b (diff) |
Fix #248 - Reload all accounts when fetching from cache
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/application_controller.rb | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index fbe4af07c..7270686de 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -61,7 +61,7 @@ class ApplicationController < ActionController::Base def cache_collection(raw, klass) return raw unless klass.respond_to?(:with_includes) - raw = raw.select(:id, :updated_at).to_a if raw.is_a?(ActiveRecord::Relation) + raw = raw.cache_ids.to_a if raw.is_a?(ActiveRecord::Relation) uncached_ids = [] cached_keys_with_value = Rails.cache.read_multi(*raw.map(&:cache_key)) @@ -69,6 +69,8 @@ class ApplicationController < ActionController::Base uncached_ids << item.id unless cached_keys_with_value.key?(item.cache_key) end + klass.reload_stale_associations!(cached_keys_with_value.values) if klass.respond_to?(:reload_stale_associations!) + unless uncached_ids.empty? uncached = klass.where(id: uncached_ids).with_includes.map { |item| [item.id, item] }.to_h |