support_table_cache 1.1.1 → 1.1.3

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: a4593056e89633a124e0301d60245fd7ce398d30c4e4df6bb83d0a982618e7e6
4
- data.tar.gz: 4a145eb106e73e8005df79dfff194fdfd1a6712a0452c5c782665321fc4f5e31
3
+ metadata.gz: 919adfaf6654d3accefd95fbba6cc116484780d0e73bc23c975da5e310c10173
4
+ data.tar.gz: 5c93b1ffc131dddc417b5de585f38ba89e4872e7d4a009705a0b8c669d7a6dd9
5
5
  SHA512:
6
- metadata.gz: d11be8910f52e30c5c7b4cdb0eb9acbb0d0c0c4921ab3eba158111ebdd9635a91387f1d440d7ccc9fdb1136b4482a0110811ba6c86eb620443011c0aa9a00b14
7
- data.tar.gz: 99df1e4070ed392e85dcb711c8cddf253733faf505d0b54d6288fb23a1c9eac67230a1a71ea05e73035133ae4fd519c0e1d9d94eb6d4d095f425faf1ca544a02
6
+ metadata.gz: 922e53c4a25b835aadf77fa0bdc18af93d70406476ab08a4ee72828dad79265203d89fef68963260666cb44cc1990bccffa0034f43376e9dc1cc632debaad87c
7
+ data.tar.gz: 756b44a620b8a6138358d23fcb4739c927d630c7e26685f173e9643d136b9ec41ddf045e77078a0bb73ada847dc46a5b952ccbb35693cd682fa0c0e8e38d92d8
data/CHANGELOG.md CHANGED
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## 1.1.3
8
+
9
+ ### Fixed
10
+ - Avoid calling methods that require a database connection when setting up belongs to caching.
11
+
12
+ ## 1.1.2
13
+
14
+ ### Fixed
15
+ - Do not cache records where only some of the columns have been loaded with a call to `select`.
16
+
7
17
  ## 1.1.1
8
18
 
9
19
  ### Fixed
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.1
1
+ 1.1.3
@@ -26,13 +26,21 @@ module SupportTableCache
26
26
  raise ArgumentError.new("Cannot cache belongs_to #{association_name} association because it has a scope")
27
27
  end
28
28
 
29
+ define_belongs_to_with_cache(association_name.to_s)
30
+ end
31
+
32
+ private
33
+
34
+ def define_belongs_to_with_cache(association_name)
29
35
  class_eval <<~RUBY, __FILE__, __LINE__ + 1
30
36
  def #{association_name}_with_cache
31
- foreign_key = self.send(#{reflection.foreign_key.inspect})
37
+ reflection = self.class.reflections[#{association_name.inspect}]
38
+ foreign_key = self.send(reflection.foreign_key)
32
39
  return nil if foreign_key.nil?
33
- key = [#{reflection.class_name.inspect}, {#{reflection.association_primary_key.inspect} => foreign_key}]
34
- cache = #{reflection.class_name}.send(:current_support_table_cache)
35
- ttl = #{reflection.class_name}.send(:support_table_cache_ttl)
40
+
41
+ key = [reflection.class_name, {reflection.association_primary_key => foreign_key}]
42
+ cache = reflection.klass.send(:current_support_table_cache)
43
+ ttl = reflection.klass.send(:support_table_cache_ttl)
36
44
  if cache
37
45
  cache.fetch(key, expires_in: ttl) do
38
46
  #{association_name}_without_cache
@@ -11,6 +11,8 @@ module SupportTableCache
11
11
  cache = klass.send(:current_support_table_cache)
12
12
  return super unless cache
13
13
 
14
+ return super if select_values.present?
15
+
14
16
  cache_key = nil
15
17
  attributes = ((args.size == 1 && args.first.is_a?(Hash)) ? args.first.stringify_keys : {})
16
18
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: support_table_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-11 00:00:00.000000000 Z
11
+ date: 2023-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord