activerecord-cached_at 2.0.13 → 6.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +89 -6
- data/lib/cached_at/associations/association.rb +1 -1
- data/lib/cached_at/associations/belongs_to_association.rb +5 -5
- data/lib/cached_at/associations/collection_association.rb +7 -5
- data/lib/cached_at/associations/collection_proxy.rb +10 -0
- data/lib/cached_at/associations/has_many_through_association.rb +4 -4
- data/lib/cached_at/associations/has_one_association.rb +2 -2
- data/lib/cached_at/base.rb +33 -9
- data/lib/cached_at/connection_adapters/abstract/schema_definitions.rb +2 -4
- data/lib/cached_at/connection_adapters/abstract/schema_statements.rb +1 -1
- data/lib/cached_at/helpers.rb +31 -7
- data/lib/cached_at/timestamp.rb +17 -10
- data/lib/cached_at/version.rb +1 -1
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ffaa40afe11c877610e9ca9ba1072e47521c6b188522cf5bba065767129f9ced
|
4
|
+
data.tar.gz: 06403fdc5c4303fc80105c5381771db103058bf0f762bd92fc0826c6afa46431
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 328f5606ca71e467cfab60b136bfe7429010f2adff5227c495916089feb03d6a98be86740fe488d833a510e7239467f192d91530d749b5fb9f67eb6a52e90e2d
|
7
|
+
data.tar.gz: ca67eddf6423cb2930860dfd00943a7ea649fd5104b03c94c0b894f087d469ad0ef88f7e7b18cccadbf6c7410d07d92074f1bf137a6bd28dba58b1692ec6e7cf
|
data/README.md
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
-
# ActiveRecord - CachedAt
|
1
|
+
# ActiveRecord - CachedAt [![Travis CI](https://travis-ci.org/malomalo/activerecord-cached_at.svg?branch=master)](https://travis-ci.org/malomalo/activerecord-cached_at)
|
2
2
|
|
3
3
|
This gem causes ActiveRecord to update a `cached_at` column if present, like the
|
4
4
|
`updated_at` column.
|
5
5
|
|
6
6
|
When calculating a `cache_key` for a model it will also consider the `cached_at`
|
7
|
-
column to
|
7
|
+
column to determine the key of a model.
|
8
8
|
|
9
9
|
Any `ActiveRecord::Migration` that calls `timestamps` will include a `cached_at`
|
10
10
|
column.
|
11
11
|
|
12
|
-
|
12
|
+
Call to [`ActiveRecord::Persistence::touch`](https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-touch)
|
13
|
+
will also touch the `cached_at` column.
|
13
14
|
|
14
15
|
## Installation
|
15
16
|
|
@@ -22,12 +23,94 @@ aren't updating the models you can just require the helpers:
|
|
22
23
|
|
23
24
|
gem 'activerecord-cached_at', require: 'cached_at/helpers'
|
24
25
|
|
26
|
+
## Configuration
|
25
27
|
|
28
|
+
By default updates to the `cached_at`, `updated_at`, and `created_at` columns
|
29
|
+
will not trigger and update to the `cached_at` column. You can add aditional
|
30
|
+
fields to ignore:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
class User
|
34
|
+
cached_at ignore: :my_column
|
35
|
+
end
|
36
|
+
|
37
|
+
class Photo
|
38
|
+
cached_at ignore: :column_a, :column_b
|
39
|
+
end
|
40
|
+
```
|
41
|
+
## Relationship Cache Keys
|
42
|
+
|
43
|
+
CachedAt also allows you to keep cache keys for relationships. This allows you
|
44
|
+
to use the record to determine if a cache is valid for a relationship instead
|
45
|
+
of doing another database query.
|
46
|
+
|
47
|
+
For example:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
class User < ActiveRecord::Base
|
51
|
+
has_many :photos
|
52
|
+
end
|
53
|
+
|
54
|
+
class Photo
|
55
|
+
belongs_to :user, cached_at: true
|
56
|
+
end
|
57
|
+
|
58
|
+
bob_ross = User.create(name: 'Bob Ross')
|
59
|
+
# => INSERT INTO "users"
|
60
|
+
# ("name", "cached_at", "updated_at_", "created_at")
|
61
|
+
# VALUES
|
62
|
+
# ("Bob Ross", "2020-07-19 20:22:03", "2020-07-19 20:22:03", "2020-07-19 20:22:03")
|
63
|
+
|
64
|
+
photo = Photo.create(user: bob_ross, file: ...)
|
65
|
+
# =>INSERT INTO "photos" ("user_id", "cached_at", "updated_at_", "created_at") VALUES (1, "Bob Ross", "2020-07-19 20:22:04", "2020-07-19 20:22:04", "2020-07-19 20:22:04")
|
66
|
+
# => UPDATE "users" SET "photos_cached_at" = "2020-07-19 20:22:04" WHERE "users"."id" = 1
|
67
|
+
|
68
|
+
photo.update(file: ...)
|
69
|
+
# =>UPDATE "photos" (..., "cached_at", "updated_at_") VALUES (..., "2020-07-19 20:22:05", "2020-07-19 20:22:05", "2020-07-19 20:22:05")
|
70
|
+
# => UPDATE "users" SET "photos_cached_at" = "2020-07-19 20:22:05" WHERE "users"."id" = 1
|
71
|
+
|
72
|
+
photo.update(user: not_bob_ross)
|
73
|
+
# =>UPDATE "photos" ("user_id", "cached_at", "updated_at_") VALUES (2, "2020-07-19 20:22:06", "2020-07-19 20:22:06", "2020-07-19 20:22:06")
|
74
|
+
# => UPDATE "users" SET "photos_cached_at" = "2020-07-19 20:22:06" WHERE "users"."id" IN (1, 2)
|
75
|
+
|
76
|
+
photo.destroy
|
77
|
+
# => UPDATE "users" SET "photos_cached_at" = "2020-07-19 20:22:07" WHERE "users"."id" = 2
|
78
|
+
# => DELETE FROM "users" WHERE WHERE "users"."id" = 2
|
79
|
+
```
|
80
|
+
|
81
|
+
# Usage
|
82
|
+
|
83
|
+
`cached_at` will automatically be used for determining the cache key in Rails.
|
84
|
+
|
85
|
+
However if you need to calculate the cache key based on relationship cache keys
|
86
|
+
you will need to manually compute the cache key. Examples are below:
|
87
|
+
|
88
|
+
The cache key here is the maxium of the following keys: `cached_at`,
|
89
|
+
`listings_cached_at`, and `photos_cached_at`
|
90
|
+
|
91
|
+
```erb
|
92
|
+
<%= render partial: 'row', collection: @properties, as: :property, cached: Proc.new { |item|
|
93
|
+
[item.cache_key_with_version(:listings, :photos), current_account.id ]
|
94
|
+
} %>
|
95
|
+
|
96
|
+
<% cache @property.cache_key_with_version(:listings, :photos) do %>
|
97
|
+
<b>All the info on this property</b>
|
98
|
+
<%= @property.name %>
|
99
|
+
<% @property.listings.each do |listing| %>
|
100
|
+
<%= listing.info %>
|
101
|
+
<% end %>
|
102
|
+
<% @property.photos.each do |photo| %>
|
103
|
+
<%= image_tag(photo.url) %>
|
104
|
+
<% end %>
|
105
|
+
<% end %>
|
106
|
+
|
107
|
+
```
|
26
108
|
## TODO:
|
27
109
|
|
28
|
-
|
110
|
+
* Document going more than one level with cached_at keys
|
29
111
|
|
112
|
+
* Add a `cache_key` method to the Model class that gets `MAX(cached_at)`
|
30
113
|
|
114
|
+
* change option to cache: true
|
31
115
|
|
32
|
-
|
33
|
-
add cache_association helper
|
116
|
+
* add cache_association helper
|
@@ -41,7 +41,7 @@ module CachedAt
|
|
41
41
|
|
42
42
|
source_assoc = owner.association(r.source_reflection_name.to_sym)
|
43
43
|
if source_assoc.loaded?
|
44
|
-
source_assoc.target.
|
44
|
+
source_assoc.target.send(:write_attribute_without_type_cast, cache_column, timestamp)
|
45
45
|
end
|
46
46
|
query = r.klass.where(r.association_primary_key => owner.send(r.foreign_key))
|
47
47
|
query.update_all({ cache_column => timestamp })
|
@@ -13,8 +13,8 @@ module CachedAt
|
|
13
13
|
|
14
14
|
cache_column = "#{options[:inverse_of]}_cached_at"
|
15
15
|
if options[:polymorphic]
|
16
|
-
oldtype = owner.send("#{reflection.foreign_type}
|
17
|
-
oldid = owner.send("#{reflection.foreign_key}
|
16
|
+
oldtype = owner.send("#{reflection.foreign_type}_before_last_save")
|
17
|
+
oldid = owner.send("#{reflection.foreign_key}_before_last_save")
|
18
18
|
newtype = owner.send(reflection.foreign_type)
|
19
19
|
newid = owner.send(reflection.foreign_key)
|
20
20
|
if !oldtype.nil? && oldtype == newtype
|
@@ -38,14 +38,14 @@ module CachedAt
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
else
|
41
|
-
ids = [owner.send(reflection.foreign_key), owner.send("#{reflection.foreign_key}
|
41
|
+
ids = [owner.send(reflection.foreign_key), owner.send("#{reflection.foreign_key}_before_last_save")].compact.uniq
|
42
42
|
query = klass.where({ reflection.association_primary_key => ids })
|
43
43
|
query.update_all({ cache_column => timestamp })
|
44
44
|
traverse_relationships(klass, options[:cached_at], query, cache_column, timestamp)
|
45
45
|
end
|
46
46
|
|
47
47
|
if loaded? && target
|
48
|
-
target.
|
48
|
+
target.send(:write_attribute_without_type_cast, cache_column, timestamp)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -54,7 +54,7 @@ module CachedAt
|
|
54
54
|
timestamp = Time.now
|
55
55
|
cache_column = "#{options[:inverse_of]}_cached_at"
|
56
56
|
if loaded? && target
|
57
|
-
target.
|
57
|
+
target.send(:write_attribute_without_type_cast, cache_column, timestamp)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -10,11 +10,13 @@ module CachedAt
|
|
10
10
|
end
|
11
11
|
|
12
12
|
cache_column = "#{reflection.inverse_of.name}_cached_at"
|
13
|
-
ids = [owner.send(reflection.association_primary_key), owner.send("#{reflection.association_primary_key}
|
13
|
+
ids = [owner.send(reflection.association_primary_key), owner.send("#{reflection.association_primary_key}_before_last_save")].compact.uniq
|
14
14
|
query = klass.where({ reflection.foreign_key => ids })
|
15
|
-
|
15
|
+
|
16
16
|
if loaded?
|
17
|
-
target.each
|
17
|
+
target.each do |record|
|
18
|
+
record.send(:write_attribute_without_type_cast, cache_column, timestamp)
|
19
|
+
end
|
18
20
|
end
|
19
21
|
|
20
22
|
if method != :destroy
|
@@ -40,14 +42,14 @@ module CachedAt
|
|
40
42
|
|
41
43
|
cache_column = "#{reflection.inverse_of.name}_cached_at"
|
42
44
|
|
43
|
-
records.each { |r| r.
|
45
|
+
records.each { |r| r.send(:write_attribute_without_type_cast, cache_column, timestamp) unless r.destroyed? }
|
44
46
|
|
45
47
|
query = klass.where({ klass.primary_key => records.map(&:id) })
|
46
48
|
query.update_all({ cache_column => timestamp })
|
47
49
|
traverse_relationships(klass, options[:cached_at], query, cache_column, timestamp)
|
48
50
|
end
|
49
51
|
|
50
|
-
def add_to_target(record, skip_callbacks
|
52
|
+
def add_to_target(record, skip_callbacks: false, replace: false, &block)
|
51
53
|
value = super
|
52
54
|
touch_records_cached_at([record], Time.now) if !(instance_variable_defined?(:@caching) && @caching)
|
53
55
|
value
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module CachedAt
|
2
|
+
module CollectionProxy
|
3
|
+
def delete(*records)
|
4
|
+
@association.touch_records_cached_at(records, Time.now) unless @association.owner.new_record?
|
5
|
+
super
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
ActiveRecord::Associations::CollectionProxy.prepend(CachedAt::CollectionProxy)
|
@@ -15,10 +15,10 @@ module CachedAt
|
|
15
15
|
|
16
16
|
query = nil
|
17
17
|
if loaded?
|
18
|
-
target.each { |r| r.
|
18
|
+
target.each { |r| r.send(:write_attribute_without_type_cast, cache_column, timestamp) }
|
19
19
|
query = klass.where(klass.primary_key => target.map(&:id))
|
20
20
|
else
|
21
|
-
ids = [owner.send(using_reflection.association_primary_key), owner.send("#{using_reflection.association_primary_key}
|
21
|
+
ids = [owner.send(using_reflection.association_primary_key), owner.send("#{using_reflection.association_primary_key}_before_last_save")].compact.uniq
|
22
22
|
arel_table = klass._reflections[using_reflection.inverse_of.options[:through].to_s].klass.arel_table
|
23
23
|
query = klass.joins(using_reflection.inverse_of.options[:through])
|
24
24
|
query = if using_reflection.is_a?(ActiveRecord::Reflection::HasAndBelongsToManyReflection)
|
@@ -35,7 +35,7 @@ module CachedAt
|
|
35
35
|
#TODO: test with new record (fails in mls)
|
36
36
|
if !owner.new_record? && using_reflection.inverse_of && using_reflection.inverse_of.options[:cached_at]
|
37
37
|
cache_column = "#{using_reflection.name}_cached_at"
|
38
|
-
owner.
|
38
|
+
owner.send(:write_attribute_without_type_cast, cache_column, timestamp)
|
39
39
|
owner.update_columns(cache_column => timestamp)
|
40
40
|
end
|
41
41
|
end
|
@@ -50,7 +50,7 @@ module CachedAt
|
|
50
50
|
end
|
51
51
|
|
52
52
|
cache_column = "#{using_reflection.inverse_of.name}_cached_at"
|
53
|
-
records.each { |r| r.
|
53
|
+
records.each { |r| r.send(:write_attribute_without_type_cast, cache_column, timestamp) }
|
54
54
|
query = klass.where(klass.primary_key => records.map(&:id))
|
55
55
|
query.update_all({ cache_column => timestamp })
|
56
56
|
traverse_relationships(klass, using_reflection.options[:cached_at], query, cache_column, timestamp)
|
@@ -10,7 +10,7 @@ module CachedAt
|
|
10
10
|
end
|
11
11
|
|
12
12
|
cache_column = "#{reflection.inverse_of.name}_cached_at"
|
13
|
-
ids = [owner.send(reflection.association_primary_key), owner.send("#{reflection.association_primary_key}
|
13
|
+
ids = [owner.send(reflection.association_primary_key), owner.send("#{reflection.association_primary_key}_before_last_save")].compact.uniq
|
14
14
|
query = klass.where({ reflection.foreign_key => ids })
|
15
15
|
|
16
16
|
case options[:dependent]
|
@@ -24,7 +24,7 @@ module CachedAt
|
|
24
24
|
end
|
25
25
|
|
26
26
|
if loaded? && target
|
27
|
-
target.
|
27
|
+
target.send(:write_attribute_without_type_cast, cache_column, timestamp)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
data/lib/cached_at/base.rb
CHANGED
@@ -3,6 +3,7 @@ require File.expand_path(File.join(__FILE__, '../associations/association'))
|
|
3
3
|
require File.expand_path(File.join(__FILE__, '../associations/has_one_association'))
|
4
4
|
require File.expand_path(File.join(__FILE__, '../associations/belongs_to_association'))
|
5
5
|
require File.expand_path(File.join(__FILE__, '../associations/collection_association'))
|
6
|
+
require File.expand_path(File.join(__FILE__, '../associations/collection_proxy'))
|
6
7
|
require File.expand_path(File.join(__FILE__, '../associations/has_many_through_association'))
|
7
8
|
|
8
9
|
require File.expand_path(File.join(__FILE__, '../reflections/abstract_reflection'))
|
@@ -12,27 +13,42 @@ module CachedAt
|
|
12
13
|
extend ActiveSupport::Concern
|
13
14
|
|
14
15
|
included do
|
16
|
+
class_attribute :cached_at_settings, default: {ignore: ['cached_at', 'updated_at', 'created_at']}
|
17
|
+
before_save :set_cached_at
|
15
18
|
before_save :update_belongs_to_cached_at_keys
|
16
19
|
before_destroy { update_relations_cached_at(method: :destroy) }
|
17
20
|
|
18
21
|
after_touch { update_relations_cached_at_from_cached_at(method: :touch) }
|
19
|
-
after_save
|
22
|
+
after_save :update_relations_cached_at_from_cached_at
|
23
|
+
end
|
24
|
+
|
25
|
+
class_methods do
|
26
|
+
def cached_at(ignore: [])
|
27
|
+
ignore = [ignore] if !ignore.is_a?(Array)
|
28
|
+
self.cached_at_settings[:ignore].push(*ignore.map(&:to_s))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def touch(*names, time: nil)
|
33
|
+
names.push('cached_at')
|
34
|
+
super(*names, time: time)
|
20
35
|
end
|
21
36
|
|
22
37
|
private
|
23
38
|
|
24
39
|
def update_relations_cached_at_from_cached_at(method: nil)
|
25
|
-
update_relations_cached_at(
|
40
|
+
update_relations_cached_at(
|
26
41
|
timestamp: (self.class.column_names.include?('cached_at') ? cached_at : nil),
|
27
42
|
method: method
|
28
|
-
|
43
|
+
)
|
29
44
|
end
|
30
45
|
|
31
46
|
def update_relations_cached_at(timestamp: nil, method: nil)
|
32
|
-
method =
|
47
|
+
method = @_new_record_before_last_commit ? :create : :update if method.nil?
|
33
48
|
|
34
|
-
|
35
|
-
return if method == :
|
49
|
+
diff = saved_changes.transform_values(&:first)
|
50
|
+
return if method == :create && diff.empty?
|
51
|
+
return if method == :update && diff.empty?
|
36
52
|
|
37
53
|
timestamp ||= current_time_from_proper_timezone
|
38
54
|
|
@@ -47,22 +63,30 @@ module CachedAt
|
|
47
63
|
end
|
48
64
|
end
|
49
65
|
|
66
|
+
def set_cached_at
|
67
|
+
return if !self.class.column_names.include?('cached_at')
|
68
|
+
diff = changes.transform_values(&:first)
|
69
|
+
return if diff.keys.all? { |k| cached_at_settings[:ignore].include?(k) }
|
70
|
+
|
71
|
+
self.cached_at = current_time_from_proper_timezone
|
72
|
+
end
|
73
|
+
|
50
74
|
def update_belongs_to_cached_at_keys
|
51
75
|
self.class.reflect_on_all_associations.each do |reflection|
|
52
76
|
next unless reflection.is_a?(ActiveRecord::Reflection::BelongsToReflection)
|
53
77
|
cache_column = "#{reflection.name}_cached_at"
|
54
78
|
|
55
79
|
if self.attribute_names.include?(cache_column)
|
56
|
-
if self.
|
80
|
+
if self.changes_to_save.has_key?(reflection.foreign_key) && self.changes_to_save[reflection.foreign_key][1].nil?
|
57
81
|
self.assign_attributes({ cache_column => current_time_from_proper_timezone })
|
58
|
-
elsif (self.
|
82
|
+
elsif (self.changes_to_save[reflection.foreign_key] || self.new_record? || (self.association(reflection.name).loaded? && self.send(reflection.name) && self.send(reflection.name).id.nil?)) && self.send(reflection.name).try(:cached_at)
|
59
83
|
self.assign_attributes({ cache_column => self.send(reflection.name).cached_at })
|
60
84
|
end
|
61
85
|
end
|
62
86
|
|
63
87
|
end
|
64
88
|
end
|
65
|
-
|
89
|
+
|
66
90
|
end
|
67
91
|
end
|
68
92
|
|
@@ -2,14 +2,12 @@ module ActiveRecord
|
|
2
2
|
module ConnectionAdapters #:nodoc:
|
3
3
|
|
4
4
|
class TableDefinition
|
5
|
-
def timestamps(
|
6
|
-
options = args.extract_options!
|
7
|
-
|
5
|
+
def timestamps(**options)
|
8
6
|
options[:null] = false if options[:null].nil?
|
9
7
|
|
10
8
|
column(:created_at, :datetime, options)
|
11
9
|
column(:updated_at, :datetime, options)
|
12
|
-
column(:cached_at,
|
10
|
+
column(:cached_at, :datetime, options)
|
13
11
|
end
|
14
12
|
end
|
15
13
|
|
@@ -7,7 +7,7 @@ module ActiveRecord
|
|
7
7
|
|
8
8
|
add_column table_name, :created_at, :datetime, options
|
9
9
|
add_column table_name, :updated_at, :datetime, options
|
10
|
-
add_column table_name, :cached_at,
|
10
|
+
add_column table_name, :cached_at, :datetime, options
|
11
11
|
end
|
12
12
|
|
13
13
|
def remove_timestamps(table_name, options = {})
|
data/lib/cached_at/helpers.rb
CHANGED
@@ -29,16 +29,40 @@ module CachedAt
|
|
29
29
|
|
30
30
|
end
|
31
31
|
|
32
|
-
def cache_key(includes
|
32
|
+
def cache_key(*includes)
|
33
33
|
if includes.nil? || includes.empty?
|
34
|
-
|
34
|
+
if cache_versioning
|
35
|
+
"#{model_name.cache_key}/#{id}"
|
36
|
+
else
|
37
|
+
"#{model_name.cache_key}/#{id}@#{cache_version}"
|
38
|
+
end
|
39
|
+
else
|
40
|
+
digest = Digest::MD5.hexdigest(paramaterize_cache_includes(includes))
|
41
|
+
if cache_versioning
|
42
|
+
"#{model_name.cache_key}/#{id}+#{digest}"
|
43
|
+
else
|
44
|
+
"#{model_name.cache_key}/#{id}+#{digest}@#{cache_version(includes)}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def cache_key_with_version(*includes)
|
50
|
+
if version = cache_version(*includes)
|
51
|
+
"#{cache_key(*includes)}-#{version}"
|
52
|
+
else
|
53
|
+
cache_key(*includes)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def cache_version(*includes)
|
58
|
+
timestamp = if includes.empty?
|
59
|
+
try(:cached_at) || try(:cached_at)
|
35
60
|
else
|
36
61
|
timestamp_keys = ['cached_at'] + self.class.cached_at_columns_for_includes(includes)
|
37
|
-
timestamp =
|
38
|
-
digest ||= Digest::MD5.new()
|
39
|
-
digest << paramaterize_cache_includes(includes)
|
40
|
-
"#{model_name.cache_key}/#{id}+#{digest.hexdigest}@#{timestamp}"
|
62
|
+
timestamp = timestamp_keys.map { |attr| self[attr]&.to_time }.compact.max
|
41
63
|
end
|
64
|
+
|
65
|
+
timestamp.utc.to_s(:usec)
|
42
66
|
end
|
43
67
|
|
44
68
|
# TODO
|
@@ -84,4 +108,4 @@ module CachedAt
|
|
84
108
|
end
|
85
109
|
end
|
86
110
|
|
87
|
-
ActiveRecord::Base.include(CachedAt::Base::Helpers)
|
111
|
+
ActiveRecord::Base.include(CachedAt::Base::Helpers)
|
data/lib/cached_at/timestamp.rb
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
module ActiveRecord
|
2
|
-
module
|
3
|
-
|
4
|
-
|
2
|
+
module CachedAt
|
3
|
+
module Timestamp
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
class_methods do
|
7
|
+
private
|
5
8
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
+
def timestamp_attributes_for_update
|
10
|
+
['updated_at']
|
11
|
+
end
|
12
|
+
|
13
|
+
def timestamp_attributes_for_create
|
14
|
+
['created_at', 'udpated_at', 'cached_at'] + column_names.select{|c| c.end_with?('_cached_at') }
|
15
|
+
end
|
9
16
|
|
10
|
-
|
11
|
-
[:created_at, :udpated_at, :cached_at] + self.class.column_names.select{|c| c.end_with?('_cached_at') }.map(&:to_sym)
|
17
|
+
end
|
12
18
|
end
|
13
|
-
|
14
19
|
end
|
15
|
-
end
|
20
|
+
end
|
21
|
+
|
22
|
+
ActiveRecord::Base.include(ActiveRecord::CachedAt::Timestamp)
|
data/lib/cached_at/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-cached_at
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.1.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Bracy
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.1.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 6.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -139,6 +139,7 @@ files:
|
|
139
139
|
- lib/cached_at/associations/association.rb
|
140
140
|
- lib/cached_at/associations/belongs_to_association.rb
|
141
141
|
- lib/cached_at/associations/collection_association.rb
|
142
|
+
- lib/cached_at/associations/collection_proxy.rb
|
142
143
|
- lib/cached_at/associations/has_many_through_association.rb
|
143
144
|
- lib/cached_at/associations/has_one_association.rb
|
144
145
|
- lib/cached_at/base.rb
|
@@ -152,7 +153,7 @@ homepage: https://github.com/malomalo/activerecord-cached_at
|
|
152
153
|
licenses:
|
153
154
|
- MIT
|
154
155
|
metadata: {}
|
155
|
-
post_install_message:
|
156
|
+
post_install_message:
|
156
157
|
rdoc_options:
|
157
158
|
- "--main"
|
158
159
|
- README.md
|
@@ -165,13 +166,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
165
166
|
version: '0'
|
166
167
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
168
|
requirements:
|
168
|
-
- - "
|
169
|
+
- - ">"
|
169
170
|
- !ruby/object:Gem::Version
|
170
|
-
version:
|
171
|
+
version: 1.3.1
|
171
172
|
requirements: []
|
172
|
-
|
173
|
-
|
174
|
-
signing_key:
|
173
|
+
rubygems_version: 3.1.4
|
174
|
+
signing_key:
|
175
175
|
specification_version: 4
|
176
176
|
summary: Allows ActiveRecord and Rails to use a `cached_at` column for the `cache_key`
|
177
177
|
if available
|