Module: Sequel::Unicache::Finder::ClassMethods

Included in:
Model
Defined in:
lib/sequel/unicache/finder.rb

Instance Method Summary collapse

Instance Method Details

#first_where(hash) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sequel/unicache/finder.rb', line 21

def first_where hash
  return primary_key_lookup hash unless hash.is_a? Hash
  if Unicache.enabled? && !Unicache.unicache_suspended? && simple_table
    config = unicache_for(*hash.keys, fuzzy: true) # need fuzzy search, this function always returns enabled config
    if config
      find_with_cache(hash, config) { super }
    else
      super
    end
  else
    super
  end
end

#primary_key_lookup(pk) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/sequel/unicache/finder.rb', line 5

def primary_key_lookup pk
  if !Unicache.enabled? || Unicache.unicache_suspended? ||
     dataset.joined_dataset? || !@fast_pk_lookup_sql
    # If it's not a simple table, simple pk,
    # assign this job to parent class, which will call first_where to do that
    super
  else
    config = unicache_for primary_key # primary key is always unicache keys, no needs to fuzzy search
    if unicache_enabled_for? config
      find_with_cache({primary_key => pk}, config) { super }
    else
      super
    end
  end
end