otr-activerecord 1.3.1 → 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: be72e7cf2d04b19487c2d747929254323747a8c06e42374814a6ecbe8bc935a2
4
- data.tar.gz: f3e1bfa5b32199891de46dbd2a9a1d633d2512c53c5d6b20fd670dc4db3b93ee
3
+ metadata.gz: f491048eedeff2cf2bb0a359e3729ddd59e6adc5003385db0d96799606cc7946
4
+ data.tar.gz: a7e388b4ab6c78461d803da7a226f98f142c74b28946738632c12c987d958f77
5
5
  SHA512:
6
- metadata.gz: 6ba9aa0f880717dac8b2eefbcc40bd2089240b60f9f1227be38b845f14180beb39e760c46d63c614cfd6f3822198724f3275dd1fe35cbc057bd307a411ef10be
7
- data.tar.gz: 263e3f0dde25f81beeecdc746951ee007470dc96e69fc869bde84d2557e150c50589d7df6c3d68ec7245fae0d221b62b9e6e905510b2182c96e924433b3251ef
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 ActiveRecord connection management in Rack apps
26
+ #### 3. Enable middleware for Rack apps
27
27
 
28
- This middleware cleans up your database connections after each request. Add it to your `config.ru` file:
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`.
@@ -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
@@ -1,6 +1,6 @@
1
1
  module OTR
2
2
  module ActiveRecord
3
3
  # Gem version
4
- VERSION = '1.3.1'
4
+ VERSION = '1.4.0'
5
5
  end
6
6
  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.3.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