Module: Lyra::Interceptors::AssociationInterceptor::HasManyAssociationPatch

Defined in:
lib/lyra/interceptors/association_interceptor.rb

Instance Method Summary collapse

Instance Method Details

#count_recordsObject

Override count_records to use cache



103
104
105
106
107
108
109
# File 'lib/lyra/interceptors/association_interceptor.rb', line 103

def count_records
  if lyra_should_use_cache?
    lyra_get_cached_relation.count
  else
    super
  end
end

#empty?Boolean

Override empty? directly

Returns:

  • (Boolean)


125
126
127
128
129
130
131
# File 'lib/lyra/interceptors/association_interceptor.rb', line 125

def empty?
  if lyra_should_use_cache?
    size == 0
  else
    super
  end
end

#find_target(async: false) ⇒ Object

Rails 8+ passes async: keyword argument to find_target



94
95
96
97
98
99
100
# File 'lib/lyra/interceptors/association_interceptor.rb', line 94

def find_target(async: false)
  if lyra_should_use_cache?
    lyra_find_target_from_cache
  else
    super
  end
end

#sizeObject

Override size to use cache (used by any?, empty?, etc.)



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/lyra/interceptors/association_interceptor.rb', line 112

def size
  if lyra_should_use_cache?
    if loaded?
      target.size
    else
      lyra_get_cached_relation.count
    end
  else
    super
  end
end