active_record_multiple_query_cache 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d2c39557d189b8d85b4e35ee4ae6f356d862cdfc
|
|
4
|
+
data.tar.gz: 7b46a465aa2b57d19e007cdca200c57c3a59880d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 897508b3089e9ff1a6f7cc7b99203df4de7db7e6fc1ef1100cb7e6c5928ec03fe27fcfa9d28d5be27adac0ffcb510db758fe4fdf9795c6bfdffb01e950f76286
|
|
7
|
+
data.tar.gz: cd1d2b0bb823a05e477077a14c5687dbbd74116621a94b2afe594074eebef80b47bba5453bb23895567a6f1806e13e43e5af73ef1af696f5dc312364f45bb725
|
data/bin/console
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
require 'active_record_multiple_query_cache'
|
|
5
5
|
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
|
@@ -10,5 +10,5 @@ require "activerecord_multiple_query_cache"
|
|
|
10
10
|
# require "pry"
|
|
11
11
|
# Pry.start
|
|
12
12
|
|
|
13
|
-
require
|
|
13
|
+
require 'irb'
|
|
14
14
|
IRB.start(__FILE__)
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
module ActiveRecordMultipleQueryCache
|
|
2
2
|
class Rails5QueryCache
|
|
3
|
-
def initialize(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
@active_record_base_class = active_record_base_class
|
|
3
|
+
def initialize(active_record_base_name_or_class)
|
|
4
|
+
@active_record_base_name_or_class = active_record_base_name_or_class
|
|
7
5
|
end
|
|
8
6
|
|
|
9
7
|
def run
|
|
10
|
-
caching_pool =
|
|
8
|
+
caching_pool = active_record_base_class.connection.pool
|
|
11
9
|
caching_was_enabled = caching_pool.query_cache_enabled
|
|
12
10
|
|
|
13
11
|
caching_pool.enable_query_cache!
|
|
@@ -18,5 +16,15 @@ module ActiveRecordMultipleQueryCache
|
|
|
18
16
|
def complete((caching_pool, caching_was_enabled))
|
|
19
17
|
caching_pool.disable_query_cache! unless caching_was_enabled
|
|
20
18
|
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def active_record_base_class
|
|
23
|
+
@active_record_base_class ||= if @active_record_base_name_or_class.is_a?(String)
|
|
24
|
+
@active_record_base_name_or_class.constantize
|
|
25
|
+
else
|
|
26
|
+
@active_record_base_name_or_class
|
|
27
|
+
end
|
|
28
|
+
end
|
|
21
29
|
end
|
|
22
30
|
end
|
|
@@ -5,14 +5,14 @@ module ActiveRecordMultipleQueryCache
|
|
|
5
5
|
autoload :Rails4QueryCache, 'active_record_multiple_query_cache/rails4_query_cache'
|
|
6
6
|
autoload :Rails5QueryCache, 'active_record_multiple_query_cache/rails5_query_cache'
|
|
7
7
|
|
|
8
|
-
def self.install_query_cache(activerecord_base_class_name, rails = Rails)
|
|
8
|
+
def self.install_query_cache(activerecord_base_class_name, rails = ::Rails)
|
|
9
9
|
if rails.gem_version >= Gem::Version.new('5.0.0')
|
|
10
10
|
executor = ActiveSupport::Executor
|
|
11
|
-
|
|
11
|
+
hook = Rails5QueryCache.new(activerecord_base_class_name)
|
|
12
12
|
|
|
13
13
|
executor.register_hook(hook)
|
|
14
14
|
else
|
|
15
|
-
middleware =
|
|
15
|
+
middleware = Rails4QueryCache.new(activerecord_base_class_name)
|
|
16
16
|
rails.configuration.app_middleware.insert_after('::ActionDispatch::Callbacks', middleware)
|
|
17
17
|
end
|
|
18
18
|
end
|