Class: RedisMemo::MemoizeQuery::CachedSelect::BindParams
- Inherits:
-
Object
- Object
- RedisMemo::MemoizeQuery::CachedSelect::BindParams
- Defined in:
- lib/redis_memo/memoize_query/cached_select/bind_params.rb
Defined Under Namespace
Classes: Plan
Instance Method Summary collapse
-
#extract! ⇒ Object
Extracted bind params is hash of sets: each key is a model class, each value is a set of hashes for memoized column conditions.
-
#initialize(left = nil, right = nil, operator = nil) ⇒ BindParams
constructor
A new instance of BindParams.
- #params ⇒ Object
- #product(other) ⇒ Object
- #should_cache? ⇒ Boolean
- #union(other) ⇒ Object
Constructor Details
#initialize(left = nil, right = nil, operator = nil) ⇒ BindParams
Returns a new instance of BindParams.
5 6 7 8 9 |
# File 'lib/redis_memo/memoize_query/cached_select/bind_params.rb', line 5 def initialize(left = nil, right = nil, operator = nil) @left = left @right = right @operator = operator end |
Instance Method Details
#extract! ⇒ Object
Extracted bind params is hash of sets: each key is a model class, each value is a set of hashes for memoized column conditions. Example:
{
Site => [
{name: 'a', city: 'b'},
{name: 'a', city: 'c'},
{name: 'b', city: 'b'},
{name: 'b', city: 'c'},
],
}
56 57 58 59 60 61 62 |
# File 'lib/redis_memo/memoize_query/cached_select/bind_params.rb', line 56 def extract! return if operator.nil? left.extract! right.extract! __send__(:"#{operator}!") end |
#params ⇒ Object
64 65 66 67 68 |
# File 'lib/redis_memo/memoize_query/cached_select/bind_params.rb', line 64 def params @params ||= Hash.new do |models, model| models[model] = Set.new end end |
#product(other) ⇒ Object
17 18 19 20 21 |
# File 'lib/redis_memo/memoize_query/cached_select/bind_params.rb', line 17 def product(other) return unless other self.class.new(self, other, __method__) end |
#should_cache? ⇒ Boolean
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/redis_memo/memoize_query/cached_select/bind_params.rb', line 23 def should_cache? plan! if plan.model_attrs.empty? || plan.dependency_size_estimation.to_i > RedisMemo::DefaultOptions.max_query_dependency_size return false end plan.model_attrs.each do |model, attrs_set| return false if attrs_set.empty? attrs_set.each do |attrs| return false unless RedisMemo::MemoizeQuery .memoized_columns(model) .include?(attrs.keys.sort) end end true end |
#union(other) ⇒ Object
11 12 13 14 15 |
# File 'lib/redis_memo/memoize_query/cached_select/bind_params.rb', line 11 def union(other) return unless other self.class.new(self, other, __method__) end |