activerecord-cached_at 2.0.7 → 2.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc1bd151e181ac5f23c935dac9ab23fbcddccbc5
4
- data.tar.gz: 208b03130f07a7e15de10eecf04f4c7b63d791a6
3
+ metadata.gz: db52a9781aef2816fbd61977be020afad8e25a9b
4
+ data.tar.gz: 1b20acad3adacdb68b1920aaaa90b82b8166dc88
5
5
  SHA512:
6
- metadata.gz: e7888c7177e10ad7dc44bc866f73b73ed046344ce365a347948cc0459e0d7267822741abe42585e24b30e55460bbe2e41240cb097d88b7b68ccc6c2078cca491
7
- data.tar.gz: 55cbee3514f01d8c156e7379d6d1d59e8a512693e944d017afaedf31adf5c2dbacc3d02e9e58ed4b032dab79c5cf58a15a08933b41969b228d5dc2059629bc6d
6
+ metadata.gz: ecdd3baaf3d1c04e795468f8cf8b6517b22f777892ee9dcdec9299202a3f41d9e579d96494deb92a56def115d9aac802239e87a203b8fba79a50e64a3a63914b
7
+ data.tar.gz: 32a7e4324a8136d5d29831856dc5041a2c47f0ffb0d5c9c03f5caadc50f526d40948e6f36f9871b6f1bad496e83a70c7a96757d4bdc33d130a043efcd269eca6
@@ -3,34 +3,40 @@ module CachedAt
3
3
 
4
4
  def touch_cached_at(timestamp, method)
5
5
  using_reflection = reflection.parent_reflection || reflection
6
- return unless using_reflection.options[:cached_at]
7
-
8
- return if method == :create && !using_reflection.is_a?(ActiveRecord::Reflection::HasAndBelongsToManyReflection)
9
-
10
- if using_reflection.inverse_of.nil?
11
- puts "WARNING: cannot updated cached at for relationship: #{owner.class.name}.#{using_reflection.name}, inverse_of not set"
12
- return
13
- end
14
6
 
15
- cache_column = "#{using_reflection.inverse_of.name}_cached_at"
7
+ if using_reflection.options[:cached_at]
8
+ return if method == :create && !using_reflection.is_a?(ActiveRecord::Reflection::HasAndBelongsToManyReflection)
9
+
10
+ if using_reflection.inverse_of.nil?
11
+ puts "WARNING: cannot updated cached at for relationship: #{owner.class.name}.#{using_reflection.name}, inverse_of not set"
12
+ return
13
+ end
14
+ cache_column = "#{using_reflection.inverse_of.name}_cached_at"
16
15
 
17
- query = nil
18
- if loaded?
19
- target.each { |r| r.raw_write_attribute(cache_column, timestamp) }
20
- query = klass.where(klass.primary_key => target.map(&:id))
21
- else
22
- ids = [owner.send(using_reflection.association_primary_key), owner.send("#{using_reflection.association_primary_key}_was")].compact.uniq
23
- arel_table = klass._reflections[using_reflection.inverse_of.options[:through].to_s].klass.arel_table
24
- query = klass.joins(using_reflection.inverse_of.options[:through])
25
- query = if using_reflection.is_a?(ActiveRecord::Reflection::HasAndBelongsToManyReflection)
26
- query.where(arel_table[using_reflection.foreign_key].in(ids))
16
+ query = nil
17
+ if loaded?
18
+ target.each { |r| r.raw_write_attribute(cache_column, timestamp) }
19
+ query = klass.where(klass.primary_key => target.map(&:id))
27
20
  else
28
- query.where(arel_table[using_reflection.inverse_of.foreign_key].in(ids))
21
+ ids = [owner.send(using_reflection.association_primary_key), owner.send("#{using_reflection.association_primary_key}_was")].compact.uniq
22
+ arel_table = klass._reflections[using_reflection.inverse_of.options[:through].to_s].klass.arel_table
23
+ query = klass.joins(using_reflection.inverse_of.options[:through])
24
+ query = if using_reflection.is_a?(ActiveRecord::Reflection::HasAndBelongsToManyReflection)
25
+ query.where(arel_table[using_reflection.foreign_key].in(ids))
26
+ else
27
+ query.where(arel_table[using_reflection.inverse_of.foreign_key].in(ids))
28
+ end
29
29
  end
30
+
31
+ query.update_all({ cache_column => timestamp })
32
+ traverse_relationships(klass, options[:cached_at], query, cache_column, timestamp)
30
33
  end
31
34
 
32
- query.update_all({ cache_column => timestamp })
33
- traverse_relationships(klass, options[:cached_at], query, cache_column, timestamp)
35
+ if using_reflection.inverse_of && using_reflection.inverse_of.options[:cached_at]
36
+ cache_column = "#{using_reflection.name}_cached_at"
37
+ owner.raw_write_attribute(cache_column, timestamp)
38
+ owner.update_columns(cache_column => timestamp)
39
+ end
34
40
  end
35
41
 
36
42
  def touch_records_cached_at(records, timestamp)
@@ -43,7 +43,6 @@ module CachedAt
43
43
  r.options[:cached_at] && r.options[:through] && r.options[:through] == reflection.inverse_of&.name
44
44
  end
45
45
  end
46
-
47
46
 
48
47
  next unless reflection.options[:cached_at] || reflection&.parent_reflection&.class == ActiveRecord::Reflection::HasAndBelongsToManyReflection || !through_connections.empty?
49
48
  next if instance_variable_defined?(:@relationships_cached_at_touched) && (!@relationships_cached_at_touched.nil? && @relationships_cached_at_touched[reflection.name])
@@ -1,3 +1,3 @@
1
1
  module CachedAt
2
- VERSION = '2.0.7'
2
+ VERSION = '2.0.8'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-cached_at
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.7
4
+ version: 2.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Bracy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-09 00:00:00.000000000 Z
11
+ date: 2017-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord