ar_cache 1.3.0 → 1.4.0

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
  SHA256:
3
- metadata.gz: 1771642ffaabd7ea8a7fc41c1ffc3cef4be12bbeaaca3ef40aa40c2f01ea291a
4
- data.tar.gz: 4b3513827e1f33d3823e0345de4e266b0312e014d1d50fbdedf52eafaa97a02c
3
+ metadata.gz: 56df5f788fb94d493c94dca6942c80819ae1fa1c567b9b6228020ad935c35c4f
4
+ data.tar.gz: 2b253f18c8174b39159f6bb0c79f298c0064a35c05ac4334719e6ca50db13a26
5
5
  SHA512:
6
- metadata.gz: c80c2bdc655f64409c1f9263415ed8fbd70aa71cb851275a7c31d8f9a459d51d46ee2fb0707c14839a37418c076e4251c55226adf7bf9aaef233d1b89faef7d0
7
- data.tar.gz: 2ad58b8a624d9e3fe559be94076b1593b54fc2f52d5f88a111d31d2c5223d4fdba6ddb9f562270fe92af99199c1aeda624e3cbfb8c97701b2b3e17f2559c184a
6
+ metadata.gz: 536189cb015607a2fd12c85f03f995ae7443b5a019e72b37526cb371a994182bad76a010c0b2f05e06be1041fee7e5bb7177ebe946155a5de73df827a66521d6
7
+ data.tar.gz: f65ea53cc987f2b3aed000408fd8b70da94dfc56a27f04db5e0aed33dac41ad7838aec761640cbff037fa7d733c5b538428154f6e082533051a20a8bf5740b52
data/CHANGELOG.md CHANGED
@@ -2,10 +2,16 @@
2
2
 
3
3
  ## main
4
4
 
5
+ ## 1.4.0 (2021-03-15 UTC)
6
+
7
+ [Commit [#7cc9ec8](https://github.com/OuYangJinTing/ar_cache/commit/7cc9ec8047394bb7758e25edd3b42fa48bb88640)]:
8
+
9
+ - Remove `ArCache::Table` `ignored_columns` configuration.
10
+ - Fix `ActiveRecord` call `#select` write to cache data is incomplete.
11
+
5
12
  ## 1.3.0 (2021-03-13 UTC)
6
13
 
7
- - [Commit [#4ec14e9](https://github.com/OuYangJinTing/ar_cache/commit/4ec14e9e762abb57a8ff18aa8c93a514db49c552)]:
8
- Optimize association cache, only cacheable association use ArCache query now.
14
+ - [Commit [#4ec14e9](https://github.com/OuYangJinTing/ar_cache/commit/4ec14e9e762abb57a8ff18aa8c93a514db49c552)]: Optimize association cache, only cacheable association use ArCache query now.
9
15
 
10
16
  ## 1.2.0 (2021-03-12 UTC)
11
17
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ar_cache (1.3.0)
4
+ ar_cache (1.4.0)
5
5
  activerecord (>= 6.1, < 7)
6
6
 
7
7
  GEM
@@ -6,6 +6,8 @@ require 'ar_cache/active_record/core'
6
6
  require 'ar_cache/active_record/persistence'
7
7
  require 'ar_cache/active_record/insert_all'
8
8
  require 'ar_cache/active_record/associations/association'
9
+ require 'ar_cache/active_record/associations/singular_association'
10
+ require 'ar_cache/active_record/associations/has_one_through_association'
9
11
  require 'ar_cache/active_record/connection_adapters/abstract/transaction'
10
12
  require 'ar_cache/active_record/connection_adapters/abstract/database_statements'
11
13
 
@@ -24,6 +26,8 @@ ActiveSupport.on_load(:active_record, run_once: true) do
24
26
  ActiveRecord::Relation.prepend(ArCache::ActiveRecord::Relation)
25
27
 
26
28
  ActiveRecord::Associations::Association.prepend(ArCache::ActiveRecord::Associations::Association)
29
+ ActiveRecord::Associations::SingularAssociation.prepend(ArCache::ActiveRecord::Associations::SingularAssociation)
30
+ ActiveRecord::Associations::HasOneThroughAssociation.prepend(ArCache::ActiveRecord::Associations::HasOneThroughAssociation)
27
31
 
28
32
  ActiveRecord::ConnectionAdapters::NullTransaction.prepend(ArCache::ActiveRecord::ConnectionAdapters::NullTransaction)
29
33
  ActiveRecord::ConnectionAdapters::RealTransaction.prepend(ArCache::ActiveRecord::ConnectionAdapters::Transaction)
@@ -4,32 +4,9 @@ module ArCache
4
4
  module ActiveRecord
5
5
  module Associations
6
6
  module Association
7
- PRELOADER = ::ActiveRecord::Associations::Preloader.new
8
-
9
7
  def reload(...)
10
8
  loaded? ? ArCache.skip { super } : super
11
9
  end
12
-
13
- # TODO: Implement CollectionAssociation cache
14
- private def find_target # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
15
- return super if ArCache.skip? || reflection.collection?
16
- return super unless ArCache.cache_reflection?(reflection) do
17
- if reflection.is_a?(::ActiveRecord::Reflection::ThroughReflection)
18
- ArCache::Query.new(owner.association(through_reflection.name).scope).exec_queries_cacheable? &&
19
- ArCache::Query.new(through_reflection.klass.new.association(reflection.source_reflection_name).scope)
20
- .exec_queries_cacheable?
21
- else
22
- ArCache::Query.new(scope).exec_queries_cacheable?
23
- end
24
- end
25
-
26
- if (owner.strict_loading? || reflection.strict_loading?) && owner.validation_context.nil?
27
- ::ActiveRecord::Base.strict_loading_violation!(owner: owner.class, reflection: reflection)
28
- end
29
-
30
- PRELOADER.preload(owner, reflection.name)
31
- Array.wrap(owner.association(reflection.name).target)
32
- end
33
10
  end
34
11
  end
35
12
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ArCache
4
+ module ActiveRecord
5
+ module Associations
6
+ module HasOneThroughAssociation
7
+ PRELOADER = ::ActiveRecord::Associations::Preloader.new
8
+
9
+ private def find_target
10
+ return super if ArCache.skip?
11
+ return super unless ArCache.cache_reflection?(reflection) do
12
+ ArCache::Query.new(owner.association(through_reflection.name).scope).exec_queries_cacheable? &&
13
+ ArCache::Query.new(source_reflection.active_record.new.association(source_reflection.name).scope)
14
+ .exec_queries_cacheable?
15
+ end
16
+
17
+ if (owner.strict_loading? || reflection.strict_loading?) && owner.validation_context.nil?
18
+ Base.strict_loading_violation!(owner: owner.class, reflection: reflection)
19
+ end
20
+
21
+ PRELOADER.preload(owner, reflection.name)
22
+ target
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ArCache
4
+ module ActiveRecord
5
+ module Associations
6
+ module SingularAssociation
7
+ private def skip_statement_cache?(...)
8
+ return super if ArCache.skip?
9
+ return true if ArCache.cache_reflection?(reflection) { ArCache::Query.new(scope).exec_queries_cacheable? }
10
+
11
+ super
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -41,7 +41,6 @@ module ArCache
41
41
  options = tables_options[name.to_sym] || {}
42
42
  options[:disabled] = disabled unless options.key?(:disabled)
43
43
  options[:select_disabled] = select_disabled unless options.key?(:select_disabled)
44
- options[:ignored_columns] = Array(options[:ignored_columns]).map(&:to_s)
45
44
  options[:unique_indexes] = Array(options[:unique_indexes]).map { |index| Array(index).map(&:to_s).uniq }.uniq
46
45
  options
47
46
  end
@@ -23,10 +23,9 @@ module ArCache
23
23
  end
24
24
 
25
25
  if missed_relation
26
- if table.ignored_columns.any? && relation.select_values.any?
27
- missed_relation = missed_relation.reselect(table.column_names)
26
+ records += relation.find_by_sql(missed_relation.arel, &block).tap do |rs|
27
+ table.write(rs) if relation.select_values.empty?
28
28
  end
29
- records += relation.find_by_sql(missed_relation.arel, &block).tap { |rs| table.write(rs) }
30
29
  end
31
30
 
32
31
  records_order(records)
@@ -43,6 +42,7 @@ module ArCache
43
42
  return false if relation.klass.ar_cache_table.disabled?
44
43
  return false if relation.skip_query_cache_value
45
44
  return false if relation.lock_value
45
+ return false if relation.distinct_value
46
46
  return false if relation.group_values.any?
47
47
  return false if relation.joins_values.any?
48
48
  return false if relation.left_outer_joins_values.any?
@@ -4,12 +4,11 @@ module ArCache
4
4
  class Table
5
5
  include Marshal
6
6
 
7
- OPTIONS = %i[disabled select_disabled unique_indexes ignored_columns].freeze
7
+ OPTIONS = %i[disabled select_disabled unique_indexes].freeze
8
8
 
9
9
  singleton_class.attr_reader :all
10
10
 
11
- attr_reader :name, :primary_key, :unique_indexes, :column_indexes, :column_names, :md5,
12
- :ignored_columns, :cache_key_prefix
11
+ attr_reader :name, :primary_key, :unique_indexes, :column_indexes, :column_names, :md5, :cache_key_prefix
13
12
 
14
13
  delegate :connection, to: ActiveRecord::Base, private: true
15
14
 
@@ -32,10 +31,10 @@ module ArCache
32
31
  @unique_indexes = normalize_unique_indexes(options.delete(:unique_indexes), columns).freeze
33
32
  options.each { |k, v| instance_variable_set("@#{k}", v) }
34
33
  @disabled = true if @primary_key.nil? # ArCache is depend on primary key implementation.
35
- @column_names = (columns.map(&:name) - @ignored_columns).freeze
34
+ @column_names = columns.map(&:name).freeze
36
35
  @column_indexes = @unique_indexes.flatten.uniq.freeze
37
36
  coder = ArCache::Configuration.coder
38
- @md5 = Digest::MD5.hexdigest("#{coder}-#{@disabled}-#{columns.to_json}-#{@ignored_columns.to_json}")
37
+ @md5 = Digest::MD5.hexdigest("#{coder}-#{@disabled}-#{columns.to_json}")
39
38
 
40
39
  ArCache::Record.store(self)
41
40
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ArCache
4
- VERSION = '1.3.0'
4
+ VERSION = '1.4.0'
5
5
  end
@@ -27,7 +27,6 @@ ArCache.configure do |config|
27
27
  # disabled: Boolean,
28
28
  # select_disabled: Boolean,
29
29
  # unique_indexes: Array # eg: [:id, [:name, :statue]], The default is the unique index column of the table.
30
- # ignored_columns: Array # eg: [:created_at, :updated_at], defaule [].
31
30
  # },
32
31
  # ...
33
32
  # }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OuYangJinTing
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-13 00:00:00.000000000 Z
11
+ date: 2021-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -58,6 +58,8 @@ files:
58
58
  - lib/ar_cache.rb
59
59
  - lib/ar_cache/active_record.rb
60
60
  - lib/ar_cache/active_record/associations/association.rb
61
+ - lib/ar_cache/active_record/associations/has_one_through_association.rb
62
+ - lib/ar_cache/active_record/associations/singular_association.rb
61
63
  - lib/ar_cache/active_record/connection_adapters/abstract/database_statements.rb
62
64
  - lib/ar_cache/active_record/connection_adapters/abstract/transaction.rb
63
65
  - lib/ar_cache/active_record/core.rb