Class: SmartCollection::Associations::Preloader::SmartCollectionCachedByCacheStore

Inherits:
ActiveRecord::Associations::Preloader::CollectionAssociation
  • Object
show all
Defined in:
lib/smart_collection/associations/preloader/smart_collection.rb

Instance Method Summary collapse

Instance Method Details

#associated_records_by_owner(preloader) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/smart_collection/associations/preloader/smart_collection.rb', line 21

def associated_records_by_owner preloader
  owners.reject(&:cache_exists?).each(&:update_cache)
  config = reflection.options[:smart_collection]
  loaded = config.cache_manager.read_multi(owners)
  records = config.item_class.where(id: loaded.values.flatten.uniq).map{|x| [x.id, x]}.to_h
  loaded.map do |owner, ids|
    [owner, ids.map{|x| records[x]}]
  end
end