module Sequel::Plugins::ConcurrentEagerLoading::DatasetMethods
Public Instance Methods
Return a cloned dataset that will eager load associated results concurrently using the async thread pool.
# File lib/sequel/plugins/concurrent_eager_loading.rb, line 123 def eager_load_concurrently cached_dataset(:_eager_load_concurrently) do clone(:eager_load_concurrently=>true) end end
Return a cloned dataset that will noteager load associated results concurrently using the async thread pool. Only useful if the current dataset has been marked as loading concurrently, or loading concurrently is the model's default behavior.
# File lib/sequel/plugins/concurrent_eager_loading.rb, line 132 def eager_load_serially cached_dataset(:_eager_load_serially) do clone(:eager_load_concurrently=>false) end end
Private Instance Methods
Whether this particular dataset will eager load results concurrently.
# File lib/sequel/plugins/concurrent_eager_loading.rb, line 141 def eager_load_concurrently? v = @opts[:eager_load_concurrently] v.nil? ? model.always_eager_load_concurrently? : v end
If performing eager loads concurrently, perform this eager load using the async thread pool.
# File lib/sequel/plugins/concurrent_eager_loading.rb, line 167 def perform_eager_load(loader, eo) eo[:mutex] ? db.send(:async_run){super} : super end
If performing eager loads concurrently, and at least 2 associations are being eagerly loaded, create a single mutex used for all eager loads. After the eager loads have been performed, force loading of any async results, so that all eager loads will have been completed before this method returns.
# File lib/sequel/plugins/concurrent_eager_loading.rb, line 150 def perform_eager_loads(eager_load_data) return super if !eager_load_concurrently? || eager_load_data.length < 2 mutex = Mutex.new eager_load_data.each_value do |eo| eo[:mutex] = mutex end super.each do |v| if Sequel::Database::AsyncThreadPool::BaseProxy === v v.__value end end end