Method: QueryDam.watch_relation

Defined in:
lib/query_dam.rb

.watch_relation(relation) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/query_dam.rb', line 13

def watch_relation(relation)
  key = SecureRandom.uuid
  query = relation.where("`#{relation.model.table_name}`.`id` = #{key}").to_sql
  query_hash = Redis::HashKey.new(key)
  query_hash.bulk_set(model: relation.model.name, query: query)
  query_hash.expire(QUERY_EXPIRE)
  Redis::Set.new(relation.model.name) << key
  key
end