otr-activerecord 1.3.1 → 1.4.0
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 +4 -4
- data/README.md +6 -2
- data/lib/otr-activerecord.rb +1 -0
- data/lib/otr-activerecord/middleware/query_cache.rb +33 -0
- data/lib/otr-activerecord/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f491048eedeff2cf2bb0a359e3729ddd59e6adc5003385db0d96799606cc7946
|
4
|
+
data.tar.gz: a7e388b4ab6c78461d803da7a226f98f142c74b28946738632c12c987d958f77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bce9596561ea97fc9aee6bd09f316041f9f366686ae33ac0d6d10d0b5d7193c2d51132636035a087b8b488f0567d624317aee9ff7ea551a10ec671ef6cf4b85b
|
7
|
+
data.tar.gz: 42d687311c29530f8a6162ceec4cd14586b30b7ee6f4da2c9398be235132370bc84d8321f58116da660f9c1947b5aed68205e4cc1820473efb389d0ccd994445
|
data/README.md
CHANGED
@@ -23,12 +23,16 @@ After loading your gems, tell `OTR::ActiveRecord` about your database config usi
|
|
23
23
|
**Important note**: `configure_from_file!` won't work as expected if you have already `DATABASE_URL` set as part of your environment variables.
|
24
24
|
This is because in ActiveRecord when that env variable is set it will merge its properties into the current connection configuration.
|
25
25
|
|
26
|
-
#### 3. Enable
|
26
|
+
#### 3. Enable middleware for Rack apps
|
27
27
|
|
28
|
-
|
28
|
+
Add these middlewares in `config.ru`:
|
29
29
|
|
30
|
+
# Clean up database connections after every request (required)
|
30
31
|
use OTR::ActiveRecord::ConnectionManagement
|
31
32
|
|
33
|
+
# Enable ActiveRecord's QueryCache for every request (optional)
|
34
|
+
use OTR::ActiveRecord::QueryCache
|
35
|
+
|
32
36
|
#### 4. Import ActiveRecord tasks into your Rakefile
|
33
37
|
|
34
38
|
This will give you most of the standard `db:` tasks you get in Rails. Add it to your `Rakefile`.
|
data/lib/otr-activerecord.rb
CHANGED
@@ -3,4 +3,5 @@ require 'hashie-forbidden_attributes'
|
|
3
3
|
require 'otr-activerecord/version'
|
4
4
|
require 'otr-activerecord/activerecord'
|
5
5
|
require 'otr-activerecord/middleware/connection_management.rb'
|
6
|
+
require 'otr-activerecord/middleware/query_cache.rb'
|
6
7
|
require 'otr-activerecord/defaults'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module OTR
|
2
|
+
module ActiveRecord
|
3
|
+
#
|
4
|
+
# Rack middleware to enable ActiveRecord's query cache for each request.
|
5
|
+
#
|
6
|
+
class QueryCache
|
7
|
+
def initialize(app)
|
8
|
+
@handler = case ::ActiveRecord::VERSION::MAJOR
|
9
|
+
when 4 then ::ActiveRecord::QueryCache.new(app)
|
10
|
+
when 5, 6 then ActionDispatchHandler.new(app)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
@handler.call(env)
|
16
|
+
end
|
17
|
+
|
18
|
+
class ActionDispatchHandler
|
19
|
+
def initialize(app)
|
20
|
+
@app = app
|
21
|
+
end
|
22
|
+
|
23
|
+
def call(env)
|
24
|
+
state = nil
|
25
|
+
state = ::ActiveRecord::QueryCache.run
|
26
|
+
@app.call(env)
|
27
|
+
ensure
|
28
|
+
::ActiveRecord::QueryCache.complete(state) if state
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: otr-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Hollinger
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- lib/otr-activerecord/compatibility_6.rb
|
61
61
|
- lib/otr-activerecord/defaults.rb
|
62
62
|
- lib/otr-activerecord/middleware/connection_management.rb
|
63
|
+
- lib/otr-activerecord/middleware/query_cache.rb
|
63
64
|
- lib/otr-activerecord/version.rb
|
64
65
|
- lib/tasks/otr-activerecord.rake
|
65
66
|
homepage: https://github.com/jhollinger/otr-activerecord
|