activerecord-cached_at 2.0.11 → 2.0.12

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: 5860c53030bc1c81930921e85181a18d967350a3
4
- data.tar.gz: c4e1b6c432bd192b59f5dbe305f372e9c5f3f112
3
+ metadata.gz: 8176a13705e644ac3fa27b5690c68ec7c4d43f46
4
+ data.tar.gz: e022fb6d8d7c6da36aa819fb3809a05a86c2f06d
5
5
  SHA512:
6
- metadata.gz: 19894074ae6826f70a9498ea336427f6f9473225a6be2e9980f259d1674e50e2cb8521ec978a5686f0959c235ce9fcfef0375ea1fc99dfe66cb409ef989f0461
7
- data.tar.gz: 74dcc58f9a1181981e44a3bb75f4ed269bd9027ef08292d5614184c5155dea9a7139d173018d979f44e9e66b503acf94ba71b398d93ae7c91d1532b4205ce507
6
+ metadata.gz: 9b0cc35ece0124d0027967d615b1665f58ca15451aa148e87f154455e4c599bedbd71dbc951b174ae12271cc9aece81a390a9124765608d66af1782edbfcdde6
7
+ data.tar.gz: 9131194d596d3fb06f205068c4afdcb6731dbd5d83902c0f5980c4bb07d875bf378332b1bd2659ed010c08a8394040162d9aa31db7e73c23e211fb980f13ce62
data/README.md CHANGED
@@ -26,3 +26,8 @@ aren't updating the models you can just require the helpers:
26
26
  ## TODO:
27
27
 
28
28
  Add a `cache_key` method to the Model class that gets `MAX(cached_at)`
29
+
30
+
31
+
32
+ change option to cache: true
33
+ add cache_association helper
@@ -2,7 +2,6 @@ module CachedAt
2
2
  module AssociationExtension
3
3
 
4
4
  def self.build(model, reflection)
5
- return unless reflection.options[:cached_at]
6
5
  end
7
6
 
8
7
  def self.valid_options
@@ -12,4 +11,4 @@ module CachedAt
12
11
  end
13
12
  end
14
13
 
15
- ActiveRecord::Associations::Builder::Association.extensions << CachedAt::AssociationExtension
14
+ ActiveRecord::Associations::Builder::Association.extensions << CachedAt::AssociationExtension
@@ -1,5 +1,9 @@
1
1
  module CachedAt
2
2
  module Association
3
+
4
+ def initialize(owner, reflection)
5
+ super
6
+ end
3
7
 
4
8
  def traverse_relationships(klass, relationships, query, cache_column, timestamp)
5
9
  if relationships.is_a?(Symbol)
@@ -35,8 +39,8 @@ module CachedAt
35
39
  end
36
40
  end
37
41
 
38
- def touch_through_reflections(reflections, timestamp)
39
- reflections.each do |r|
42
+ def touch_through_reflections(timestamp)
43
+ reflection.through_relationship_endpoints.each do |r|
40
44
  cache_column = "#{r.inverse_of.name}_cached_at"
41
45
 
42
46
  source_assoc = owner.association(r.source_reflection_name.to_sym)
@@ -5,6 +5,8 @@ require File.expand_path(File.join(__FILE__, '../associations/belongs_to_associa
5
5
  require File.expand_path(File.join(__FILE__, '../associations/collection_association'))
6
6
  require File.expand_path(File.join(__FILE__, '../associations/has_many_through_association'))
7
7
 
8
+ require File.expand_path(File.join(__FILE__, '../reflections/abstract_reflection'))
9
+
8
10
  module CachedAt
9
11
  module Base
10
12
  extend ActiveSupport::Concern
@@ -35,22 +37,13 @@ module CachedAt
35
37
  timestamp ||= current_time_from_proper_timezone
36
38
 
37
39
  self._reflections.each do |name, reflection|
38
-
39
- through_connections = if reflection.polymorphic?
40
- []
41
- else
42
- reflection.klass._reflections.values.select do |r|
43
- r.options[:cached_at] && r.options[:through] && r.options[:through] == reflection.inverse_of&.name
44
- end
45
- end
46
-
47
- next unless reflection.options[:cached_at] || reflection&.parent_reflection&.class == ActiveRecord::Reflection::HasAndBelongsToManyReflection || !through_connections.empty?
40
+ next unless reflection.options[:cached_at] || reflection&.parent_reflection&.class == ActiveRecord::Reflection::HasAndBelongsToManyReflection || !reflection.through_relationship_endpoints.empty?
48
41
  next if instance_variable_defined?(:@relationships_cached_at_touched) && (!@relationships_cached_at_touched.nil? && @relationships_cached_at_touched[reflection.name])
49
42
  next if reflection.is_a?(ActiveRecord::Reflection::HasManyReflection) && method == :create
50
43
 
51
44
  assoc = association(name.to_sym)
52
45
  assoc.touch_cached_at(timestamp, method)
53
- assoc.touch_through_reflections(through_connections, timestamp)
46
+ assoc.touch_through_reflections(timestamp)
54
47
  end
55
48
  end
56
49
 
@@ -0,0 +1,30 @@
1
+ module CachedAt
2
+ module AbstractReflection
3
+
4
+ def through_relationship_endpoints
5
+ return @through_relationship_endpoints if instance_variable_defined?(:@through_relationship_endpoints)
6
+
7
+ @through_relationship_endpoints = []
8
+ active_record.reflections.each do |name, r|
9
+ next if r == self
10
+ begin
11
+ if r.polymorphic?
12
+ # TODO
13
+ else
14
+ r.klass.reflections.each do |name2, r2|
15
+ if r2.options[:cached_at] && r2.options[:through] && r2.options[:through] == r.inverse_of&.name
16
+ @through_relationship_endpoints << r2
17
+ end
18
+ end
19
+ end
20
+ rescue NameError
21
+ end
22
+ end
23
+
24
+ @through_relationship_endpoints
25
+ end
26
+
27
+ end
28
+ end
29
+
30
+ ActiveRecord::Reflection::AbstractReflection.include(CachedAt::AbstractReflection)
@@ -1,3 +1,3 @@
1
1
  module CachedAt
2
- VERSION = '2.0.11'
2
+ VERSION = '2.0.12'
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.11
4
+ version: 2.0.12
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-10 00:00:00.000000000 Z
11
+ date: 2017-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -145,6 +145,7 @@ files:
145
145
  - lib/cached_at/connection_adapters/abstract/schema_definitions.rb
146
146
  - lib/cached_at/connection_adapters/abstract/schema_statements.rb
147
147
  - lib/cached_at/helpers.rb
148
+ - lib/cached_at/reflections/abstract_reflection.rb
148
149
  - lib/cached_at/timestamp.rb
149
150
  - lib/cached_at/version.rb
150
151
  homepage: https://github.com/malomalo/activerecord-cached_at
@@ -169,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
170
  version: '0'
170
171
  requirements: []
171
172
  rubyforge_project:
172
- rubygems_version: 2.5.2
173
+ rubygems_version: 2.5.1
173
174
  signing_key:
174
175
  specification_version: 4
175
176
  summary: Allows ActiveRecord and Rails to use a `cached_at` column for the `cache_key`