activerecord-cached_at 6.1.0.rc1 → 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/ext/active_record/connection_adapters/abstract/schema_definitions.rb +12 -5
- data/ext/active_record/connection_adapters/abstract/schema_statements.rb +28 -5
- data/lib/cached_at/associations/association.rb +2 -1
- data/lib/cached_at/associations/belongs_to_association.rb +4 -2
- data/lib/cached_at/associations/collection_association.rb +8 -2
- data/lib/cached_at/associations/has_many_through_association.rb +10 -3
- data/lib/cached_at/associations/has_one_association.rb +2 -1
- data/lib/cached_at/timestamp.rb +4 -2
- data/lib/cached_at/version.rb +1 -1
- data/lib/cached_at.rb +2 -2
- metadata +7 -9
- data/lib/cached_at/connection_adapters/abstract/schema_definitions.rb +0 -15
- data/lib/cached_at/connection_adapters/abstract/schema_statements.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79e3b29684f0a17923d328876ac4cfa8e839a4f8ce8d5c11f8cb57961a737b1a
|
4
|
+
data.tar.gz: 0a9a34b66da4bc0019b9cebaa5a35befb1a442711fe2660553d0362f9ac5936a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5f8b1069214be9721b925c4e41fab372a04c0dadcea5bff50caffd1f87a00342453ea318ffc3f64851532c281530b7929f9d5d9cddf93f31786139a450a56aa
|
7
|
+
data.tar.gz: cb5fe100c8103e71378fdfb78762e74723ca8822dbf8387148fcdf568371e918780eb95faa201b50f82b63d798039cf175b00c27e9b4e5ff81fb7e374a3f29f4
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# ActiveRecord - CachedAt
|
1
|
+
# ActiveRecord - CachedAt
|
2
2
|
|
3
3
|
This gem causes ActiveRecord to update a `cached_at` column if present, like the
|
4
4
|
`updated_at` column.
|
@@ -2,14 +2,21 @@ module ActiveRecord
|
|
2
2
|
module ConnectionAdapters #:nodoc:
|
3
3
|
|
4
4
|
class TableDefinition
|
5
|
-
def timestamps(*args)
|
6
|
-
options = args.extract_options!
|
7
5
|
|
6
|
+
def internal_table?
|
7
|
+
@name == "#{ActiveRecord::Base.table_name_prefix}#{ActiveRecord::Base.internal_metadata_table_name}#{ActiveRecord::Base.table_name_suffix}"
|
8
|
+
end
|
9
|
+
|
10
|
+
def timestamps(**options)
|
8
11
|
options[:null] = false if options[:null].nil?
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
+
if !options.key?(:precision) && @conn.supports_datetime_with_precision?
|
14
|
+
options[:precision] = 6
|
15
|
+
end
|
16
|
+
|
17
|
+
column(:created_at, :datetime, **options)
|
18
|
+
column(:updated_at, :datetime, **options)
|
19
|
+
column(:cached_at, :datetime, **options) if !internal_table?
|
13
20
|
end
|
14
21
|
end
|
15
22
|
|
@@ -2,19 +2,42 @@ module ActiveRecord
|
|
2
2
|
module ConnectionAdapters #:nodoc:
|
3
3
|
|
4
4
|
module SchemaStatements
|
5
|
-
def add_timestamps(table_name, options
|
5
|
+
def add_timestamps(table_name, **options)
|
6
6
|
options[:null] = false if options[:null].nil?
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
if !options.key?(:precision) && supports_datetime_with_precision?
|
9
|
+
options[:precision] = 6
|
10
|
+
end
|
11
|
+
|
12
|
+
add_column table_name, :created_at, :datetime, **options
|
13
|
+
add_column table_name, :updated_at, :datetime, **options
|
14
|
+
add_column table_name, :cached_at, :datetime, **options
|
11
15
|
end
|
12
16
|
|
13
|
-
def remove_timestamps(table_name, options
|
17
|
+
def remove_timestamps(table_name, **options)
|
14
18
|
remove_column table_name, :updated_at
|
15
19
|
remove_column table_name, :created_at
|
16
20
|
remove_column table_name, :cached_at
|
17
21
|
end
|
22
|
+
|
23
|
+
def add_timestamps_for_alter(table_name, **options)
|
24
|
+
options[:null] = false if options[:null].nil?
|
25
|
+
|
26
|
+
if !options.key?(:precision) && supports_datetime_with_precision?
|
27
|
+
options[:precision] = 6
|
28
|
+
end
|
29
|
+
|
30
|
+
[
|
31
|
+
add_column_for_alter(table_name, :created_at, :datetime, **options),
|
32
|
+
add_column_for_alter(table_name, :updated_at, :datetime, **options),
|
33
|
+
add_column_for_alter(table_name, :cached_at, :datetime, **options)
|
34
|
+
]
|
35
|
+
end
|
36
|
+
|
37
|
+
def remove_timestamps_for_alter(table_name, **options)
|
38
|
+
remove_columns_for_alter(table_name, :updated_at, :created_at, :cached_at)
|
39
|
+
end
|
40
|
+
|
18
41
|
end
|
19
42
|
|
20
43
|
end
|
@@ -41,7 +41,8 @@ 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.instance_variable_get(:@attributes).write_cast_value(cache_column, timestamp)
|
45
|
+
source_assoc.target.send(:clear_attribute_change, cache_column)
|
45
46
|
end
|
46
47
|
query = r.klass.where(r.association_primary_key => owner.send(r.foreign_key))
|
47
48
|
query.update_all({ cache_column => timestamp })
|
@@ -45,7 +45,8 @@ module CachedAt
|
|
45
45
|
end
|
46
46
|
|
47
47
|
if loaded? && target
|
48
|
-
target.
|
48
|
+
target.instance_variable_get(:@attributes).write_cast_value(cache_column, timestamp)
|
49
|
+
target.send(:clear_attribute_change, cache_column)
|
49
50
|
end
|
50
51
|
end
|
51
52
|
|
@@ -54,7 +55,8 @@ module CachedAt
|
|
54
55
|
timestamp = Time.now
|
55
56
|
cache_column = "#{options[:inverse_of]}_cached_at"
|
56
57
|
if loaded? && target
|
57
|
-
target.
|
58
|
+
target.instance_variable_get(:@attributes).write_cast_value(cache_column, timestamp)
|
59
|
+
target.send(:clear_attribute_change, cache_column)
|
58
60
|
end
|
59
61
|
end
|
60
62
|
|
@@ -15,7 +15,8 @@ module CachedAt
|
|
15
15
|
|
16
16
|
if loaded?
|
17
17
|
target.each do |record|
|
18
|
-
record.
|
18
|
+
record.instance_variable_get(:@attributes).write_cast_value(cache_column, timestamp)
|
19
|
+
record.send(:clear_attribute_change, cache_column)
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
@@ -42,7 +43,12 @@ module CachedAt
|
|
42
43
|
|
43
44
|
cache_column = "#{reflection.inverse_of.name}_cached_at"
|
44
45
|
|
45
|
-
records.each
|
46
|
+
records.each do |record|
|
47
|
+
next if record.destroyed?
|
48
|
+
|
49
|
+
record.instance_variable_get(:@attributes).write_cast_value(cache_column, timestamp)
|
50
|
+
record.send(:clear_attribute_change, cache_column)
|
51
|
+
end
|
46
52
|
|
47
53
|
query = klass.where({ klass.primary_key => records.map(&:id) })
|
48
54
|
query.update_all({ cache_column => timestamp })
|
@@ -15,7 +15,10 @@ module CachedAt
|
|
15
15
|
|
16
16
|
query = nil
|
17
17
|
if loaded?
|
18
|
-
target.each
|
18
|
+
target.each do |record|
|
19
|
+
record.instance_variable_get(:@attributes).write_cast_value(cache_column, timestamp)
|
20
|
+
record.send(:clear_attribute_change, cache_column)
|
21
|
+
end
|
19
22
|
query = klass.where(klass.primary_key => target.map(&:id))
|
20
23
|
else
|
21
24
|
ids = [owner.send(using_reflection.association_primary_key), owner.send("#{using_reflection.association_primary_key}_before_last_save")].compact.uniq
|
@@ -35,7 +38,8 @@ module CachedAt
|
|
35
38
|
#TODO: test with new record (fails in mls)
|
36
39
|
if !owner.new_record? && using_reflection.inverse_of && using_reflection.inverse_of.options[:cached_at]
|
37
40
|
cache_column = "#{using_reflection.name}_cached_at"
|
38
|
-
owner.
|
41
|
+
owner.instance_variable_get(:@attributes).write_cast_value(cache_column, timestamp)
|
42
|
+
owner.send(:clear_attribute_change, cache_column)
|
39
43
|
owner.update_columns(cache_column => timestamp)
|
40
44
|
end
|
41
45
|
end
|
@@ -50,7 +54,10 @@ module CachedAt
|
|
50
54
|
end
|
51
55
|
|
52
56
|
cache_column = "#{using_reflection.inverse_of.name}_cached_at"
|
53
|
-
records.each
|
57
|
+
records.each do |record|
|
58
|
+
record.instance_variable_get(:@attributes).write_cast_value(cache_column, timestamp)
|
59
|
+
record.send(:clear_attribute_change, cache_column)
|
60
|
+
end
|
54
61
|
query = klass.where(klass.primary_key => records.map(&:id))
|
55
62
|
query.update_all({ cache_column => timestamp })
|
56
63
|
traverse_relationships(klass, using_reflection.options[:cached_at], query, cache_column, timestamp)
|
@@ -24,7 +24,8 @@ module CachedAt
|
|
24
24
|
end
|
25
25
|
|
26
26
|
if loaded? && target
|
27
|
-
target.
|
27
|
+
target.instance_variable_get(:@attributes).write_cast_value(cache_column, timestamp)
|
28
|
+
target.send(:clear_attribute_change, cache_column)
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
data/lib/cached_at/timestamp.rb
CHANGED
@@ -7,11 +7,13 @@ module ActiveRecord
|
|
7
7
|
private
|
8
8
|
|
9
9
|
def timestamp_attributes_for_update
|
10
|
-
[
|
10
|
+
["updated_at", "updated_on"].map! { |name| attribute_aliases[name] || name }
|
11
11
|
end
|
12
12
|
|
13
13
|
def timestamp_attributes_for_create
|
14
|
-
['created_at', 'udpated_at', 'cached_at'] + column_names.select{|c| c.end_with?('_cached_at') }
|
14
|
+
(['created_at', 'udpated_at', 'cached_at'] + column_names.select{|c| c.end_with?('_cached_at') }).map! do |name|
|
15
|
+
attribute_aliases[name] || name
|
16
|
+
end
|
15
17
|
end
|
16
18
|
|
17
19
|
end
|
data/lib/cached_at/version.rb
CHANGED
data/lib/cached_at.rb
CHANGED
@@ -3,5 +3,5 @@ require 'active_record'
|
|
3
3
|
require File.expand_path(File.join(__FILE__, '../cached_at/base'))
|
4
4
|
require File.expand_path(File.join(__FILE__, '../cached_at/helpers'))
|
5
5
|
require File.expand_path(File.join(__FILE__, '../cached_at/timestamp'))
|
6
|
-
require File.expand_path(File.join(__FILE__, '
|
7
|
-
require File.expand_path(File.join(__FILE__, '
|
6
|
+
require File.expand_path(File.join(__FILE__, '../../ext/active_record/connection_adapters/abstract/schema_definitions'))
|
7
|
+
require File.expand_path(File.join(__FILE__, '../../ext/active_record/connection_adapters/abstract/schema_statements'))
|
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:
|
4
|
+
version: 7.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Bracy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 7.0.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: 7.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -143,8 +143,6 @@ files:
|
|
143
143
|
- lib/cached_at/associations/has_many_through_association.rb
|
144
144
|
- lib/cached_at/associations/has_one_association.rb
|
145
145
|
- lib/cached_at/base.rb
|
146
|
-
- lib/cached_at/connection_adapters/abstract/schema_definitions.rb
|
147
|
-
- lib/cached_at/connection_adapters/abstract/schema_statements.rb
|
148
146
|
- lib/cached_at/helpers.rb
|
149
147
|
- lib/cached_at/reflections/abstract_reflection.rb
|
150
148
|
- lib/cached_at/timestamp.rb
|
@@ -166,11 +164,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
166
164
|
version: '0'
|
167
165
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
166
|
requirements:
|
169
|
-
- - "
|
167
|
+
- - ">="
|
170
168
|
- !ruby/object:Gem::Version
|
171
|
-
version:
|
169
|
+
version: '0'
|
172
170
|
requirements: []
|
173
|
-
rubygems_version: 3.
|
171
|
+
rubygems_version: 3.4.13
|
174
172
|
signing_key:
|
175
173
|
specification_version: 4
|
176
174
|
summary: Allows ActiveRecord and Rails to use a `cached_at` column for the `cache_key`
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module ConnectionAdapters #:nodoc:
|
3
|
-
|
4
|
-
class TableDefinition
|
5
|
-
def timestamps(**options)
|
6
|
-
options[:null] = false if options[:null].nil?
|
7
|
-
|
8
|
-
column(:created_at, :datetime, options)
|
9
|
-
column(:updated_at, :datetime, options)
|
10
|
-
column(:cached_at, :datetime, options)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module ConnectionAdapters #:nodoc:
|
3
|
-
|
4
|
-
module SchemaStatements
|
5
|
-
def add_timestamps(table_name, options = {})
|
6
|
-
options[:null] = false if options[:null].nil?
|
7
|
-
|
8
|
-
add_column table_name, :created_at, :datetime, options
|
9
|
-
add_column table_name, :updated_at, :datetime, options
|
10
|
-
add_column table_name, :cached_at, :datetime, options
|
11
|
-
end
|
12
|
-
|
13
|
-
def remove_timestamps(table_name, options = {})
|
14
|
-
remove_column table_name, :updated_at
|
15
|
-
remove_column table_name, :created_at
|
16
|
-
remove_column table_name, :cached_at
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|