advanced_connection 0.5.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.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.gitignore +8 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +63 -0
  6. data/Gemfile +3 -0
  7. data/Gemfile.lock +218 -0
  8. data/MIT-LICENSE +20 -0
  9. data/README.rdoc +3 -0
  10. data/Rakefile +165 -0
  11. data/advanced_connection.gemspec +49 -0
  12. data/gemfiles/jruby/rails4_1.gemfile +7 -0
  13. data/gemfiles/jruby/rails4_2.gemfile +7 -0
  14. data/gemfiles/ruby/rails4_1.gemfile +7 -0
  15. data/gemfiles/ruby/rails4_2.gemfile +7 -0
  16. data/lib/advanced_connection/active_record_ext/abstract_adapter/statement_pooling.rb +121 -0
  17. data/lib/advanced_connection/active_record_ext/abstract_adapter.rb +48 -0
  18. data/lib/advanced_connection/active_record_ext/connection_pool/idle_manager.rb +271 -0
  19. data/lib/advanced_connection/active_record_ext/connection_pool/queues.rb +60 -0
  20. data/lib/advanced_connection/active_record_ext/connection_pool/statement_pooling.rb +42 -0
  21. data/lib/advanced_connection/active_record_ext/connection_pool/without_connection.rb +93 -0
  22. data/lib/advanced_connection/active_record_ext/connection_pool.rb +38 -0
  23. data/lib/advanced_connection/active_record_ext/without_connection.rb +30 -0
  24. data/lib/advanced_connection/active_record_ext.rb +59 -0
  25. data/lib/advanced_connection/config.rb +247 -0
  26. data/lib/advanced_connection/error.rb +27 -0
  27. data/lib/advanced_connection/railtie.rb +40 -0
  28. data/lib/advanced_connection/version.rb +29 -0
  29. data/lib/advanced_connection.rb +65 -0
  30. data/lib/generators/advanced_connection/install/USAGE +5 -0
  31. data/lib/generators/advanced_connection/install/install_generator.rb +30 -0
  32. data/lib/generators/advanced_connection/install/templates/advanced_connection.rb +142 -0
  33. data/lib/tasks/advanced_connection_tasks.rake +25 -0
  34. data/spec/config/database.yml +18 -0
  35. data/spec/config/database.yml.erb +54 -0
  36. data/spec/dummy/.gitignore +1 -0
  37. data/spec/dummy/README.rdoc +28 -0
  38. data/spec/dummy/Rakefile +6 -0
  39. data/spec/dummy/app/assets/images/.keep +0 -0
  40. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  41. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  42. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  43. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  44. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  45. data/spec/dummy/app/mailers/.keep +0 -0
  46. data/spec/dummy/app/models/.keep +0 -0
  47. data/spec/dummy/app/models/book.rb +2 -0
  48. data/spec/dummy/app/models/concerns/.keep +0 -0
  49. data/spec/dummy/app/views/layouts/application.html.erb +13 -0
  50. data/spec/dummy/bin/bundle +3 -0
  51. data/spec/dummy/bin/rails +4 -0
  52. data/spec/dummy/bin/rake +4 -0
  53. data/spec/dummy/bin/setup +29 -0
  54. data/spec/dummy/config/application.rb +32 -0
  55. data/spec/dummy/config/boot.rb +5 -0
  56. data/spec/dummy/config/database.yml +17 -0
  57. data/spec/dummy/config/environment.rb +5 -0
  58. data/spec/dummy/config/environments/development.rb +48 -0
  59. data/spec/dummy/config/environments/production.rb +79 -0
  60. data/spec/dummy/config/environments/test.rb +42 -0
  61. data/spec/dummy/config/initializers/advanced_connection.rb +142 -0
  62. data/spec/dummy/config/initializers/assets.rb +11 -0
  63. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  64. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  65. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  66. data/spec/dummy/config/initializers/inflections.rb +16 -0
  67. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  68. data/spec/dummy/config/initializers/session_store.rb +3 -0
  69. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  70. data/spec/dummy/config/locales/en.yml +23 -0
  71. data/spec/dummy/config/routes.rb +56 -0
  72. data/spec/dummy/config/secrets.yml +22 -0
  73. data/spec/dummy/config.ru +4 -0
  74. data/spec/dummy/db/migrate/20160222045238_create_books.rb +10 -0
  75. data/spec/dummy/db/schema.rb +23 -0
  76. data/spec/dummy/lib/assets/.keep +0 -0
  77. data/spec/dummy/log/.keep +0 -0
  78. data/spec/dummy/log/test.log +327 -0
  79. data/spec/dummy/public/404.html +67 -0
  80. data/spec/dummy/public/422.html +67 -0
  81. data/spec/dummy/public/500.html +66 -0
  82. data/spec/dummy/public/favicon.ico +0 -0
  83. data/spec/dummy/test/fixtures/books.yml +9 -0
  84. data/spec/dummy/test/models/book_test.rb +7 -0
  85. data/spec/idle_manager_spec.rb +16 -0
  86. data/spec/spec_helper.rb +25 -0
  87. data/spec/support/db_config.rb +61 -0
  88. metadata +399 -0
@@ -0,0 +1 @@
1
+ log/*.log
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
File without changes
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
File without changes
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
File without changes
File without changes
@@ -0,0 +1,2 @@
1
+ class Book < ActiveRecord::Base
2
+ end
File without changes
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all' %>
6
+ <%= csrf_meta_tags %>
7
+ </head>
8
+ <body>
9
+
10
+ <%= yield %>
11
+
12
+ </body>
13
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
+
7
+ Dir.chdir APP_ROOT do
8
+ # This script is a starting point to setup your application.
9
+ # Add necessary setup steps to this file:
10
+
11
+ puts "== Installing dependencies =="
12
+ system "gem install bundler --conservative"
13
+ system "bundle check || bundle install"
14
+
15
+ # puts "\n== Copying sample files =="
16
+ # unless File.exist?("config/database.yml")
17
+ # system "cp config/database.yml.sample config/database.yml"
18
+ # end
19
+
20
+ puts "\n== Preparing database =="
21
+ system "bin/rake db:setup"
22
+
23
+ puts "\n== Removing old logs and tempfiles =="
24
+ system "rm -f log/*"
25
+ system "rm -rf tmp/cache"
26
+
27
+ puts "\n== Restarting application server =="
28
+ system "touch tmp/restart.txt"
29
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ # Pick the frameworks you want:
4
+ require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_mailer/railtie"
7
+ require "action_view/railtie"
8
+ # require "sprockets/railtie"
9
+ require "rails/test_unit/railtie"
10
+
11
+ Bundler.require(*Rails.groups)
12
+ require "advanced_connection"
13
+
14
+ module Dummy
15
+ class Application < Rails::Application
16
+ # Settings in config/environments/* take precedence over those specified here.
17
+ # Application configuration should go into files in config/initializers
18
+ # -- all .rb files in that directory are automatically loaded.
19
+
20
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
21
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
22
+ # config.time_zone = 'Central Time (US & Canada)'
23
+
24
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
25
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
26
+ # config.i18n.default_locale = :de
27
+
28
+ # Do not swallow errors in after_commit/after_rollback callbacks.
29
+ config.active_record.raise_in_transactional_callbacks = true
30
+ end
31
+ end
32
+
@@ -0,0 +1,5 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,17 @@
1
+ ---
2
+ development: &1
3
+ pool: 50
4
+ timeout: 5000
5
+ queue_type: :prefer_older
6
+ min_idle_connections: 5
7
+ max_idle_connections: 10
8
+ warmup_connections: 20
9
+ dead_connection_timeout: 15
10
+ reaping_frequency: 15
11
+ adapter: postgresql
12
+ database: advanced_connection_test
13
+ username: postgres
14
+ min_messages: WARNING
15
+ schema_search_path: public
16
+ password:
17
+ test: *1
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!
@@ -0,0 +1,48 @@
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ if "irb" == $0
5
+ config.logger = Logger.new(Rails.root.join('log', "#{Rails.env}.log"))
6
+ end
7
+
8
+ config.log_level = :debug
9
+ config.log_formatter = ::Logger::Formatter.new
10
+
11
+ # In the development environment your application's code is reloaded on
12
+ # every request. This slows down response time but is perfect for development
13
+ # since you don't have to restart the web server when you make code changes.
14
+ config.cache_classes = false
15
+
16
+ # Do not eager load code on boot.
17
+ config.eager_load = false
18
+
19
+ # Show full error reports and disable caching.
20
+ config.consider_all_requests_local = true
21
+ config.action_controller.perform_caching = false
22
+
23
+ # Don't care if the mailer can't send.
24
+ config.action_mailer.raise_delivery_errors = false
25
+
26
+ # Print deprecation notices to the Rails logger.
27
+ config.active_support.deprecation = :log
28
+
29
+ # Raise an error on page load if there are pending migrations.
30
+ config.active_record.migration_error = :page_load
31
+
32
+ # Debug mode disables concatenation and preprocessing of assets.
33
+ # This option may cause significant delays in view rendering with a large
34
+ # number of complex assets.
35
+ config.assets.debug = true
36
+
37
+ # Asset digests allow you to set far-future HTTP expiration dates on all assets,
38
+ # yet still be able to expire them through the digest params.
39
+ config.assets.digest = true
40
+
41
+ # Adds additional error checking when serving assets at runtime.
42
+ # Checks for improperly declared sprockets dependencies.
43
+ # Raises helpful error messages.
44
+ config.assets.raise_runtime_errors = true
45
+
46
+ # Raises error for missing translations
47
+ # config.action_view.raise_on_missing_translations = true
48
+ end
@@ -0,0 +1,79 @@
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # Code is not reloaded between requests.
5
+ config.cache_classes = true
6
+
7
+ # Eager load code on boot. This eager loads most of Rails and
8
+ # your application in memory, allowing both threaded web servers
9
+ # and those relying on copy on write to perform better.
10
+ # Rake tasks automatically ignore this option for performance.
11
+ config.eager_load = true
12
+
13
+ # Full error reports are disabled and caching is turned on.
14
+ config.consider_all_requests_local = false
15
+ config.action_controller.perform_caching = true
16
+
17
+ # Enable Rack::Cache to put a simple HTTP cache in front of your application
18
+ # Add `rack-cache` to your Gemfile before enabling this.
19
+ # For large-scale production use, consider using a caching reverse proxy like
20
+ # NGINX, varnish or squid.
21
+ # config.action_dispatch.rack_cache = true
22
+
23
+ # Disable serving static files from the `/public` folder by default since
24
+ # Apache or NGINX already handles this.
25
+ config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
26
+
27
+ # Compress JavaScripts and CSS.
28
+ config.assets.js_compressor = :uglifier
29
+ # config.assets.css_compressor = :sass
30
+
31
+ # Do not fallback to assets pipeline if a precompiled asset is missed.
32
+ config.assets.compile = false
33
+
34
+ # Asset digests allow you to set far-future HTTP expiration dates on all assets,
35
+ # yet still be able to expire them through the digest params.
36
+ config.assets.digest = true
37
+
38
+ # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
39
+
40
+ # Specifies the header that your server uses for sending files.
41
+ # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
42
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
43
+
44
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
45
+ # config.force_ssl = true
46
+
47
+ # Use the lowest log level to ensure availability of diagnostic information
48
+ # when problems arise.
49
+ config.log_level = :debug
50
+
51
+ # Prepend all log lines with the following tags.
52
+ # config.log_tags = [ :subdomain, :uuid ]
53
+
54
+ # Use a different logger for distributed setups.
55
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
56
+
57
+ # Use a different cache store in production.
58
+ # config.cache_store = :mem_cache_store
59
+
60
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
61
+ # config.action_controller.asset_host = 'http://assets.example.com'
62
+
63
+ # Ignore bad email addresses and do not raise email delivery errors.
64
+ # Set this to true and configure the email server for immediate delivery to raise delivery errors.
65
+ # config.action_mailer.raise_delivery_errors = false
66
+
67
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
68
+ # the I18n.default_locale when a translation cannot be found).
69
+ config.i18n.fallbacks = true
70
+
71
+ # Send deprecation notices to registered listeners.
72
+ config.active_support.deprecation = :notify
73
+
74
+ # Use default logging formatter so that PID and timestamp are not suppressed.
75
+ config.log_formatter = ::Logger::Formatter.new
76
+
77
+ # Do not dump schema after migrations.
78
+ config.active_record.dump_schema_after_migration = false
79
+ end
@@ -0,0 +1,42 @@
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Do not eager load code on boot. This avoids loading your whole application
11
+ # just for the purpose of running a single test. If you are using a tool that
12
+ # preloads Rails for running tests, you may have to set it to true.
13
+ config.eager_load = false
14
+
15
+ # Configure static file server for tests with Cache-Control for performance.
16
+ config.serve_static_files = true
17
+ config.static_cache_control = 'public, max-age=3600'
18
+
19
+ # Show full error reports and disable caching.
20
+ config.consider_all_requests_local = true
21
+ config.action_controller.perform_caching = false
22
+
23
+ # Raise exceptions instead of rendering exception templates.
24
+ config.action_dispatch.show_exceptions = false
25
+
26
+ # Disable request forgery protection in test environment.
27
+ config.action_controller.allow_forgery_protection = false
28
+
29
+ # Tell Action Mailer not to deliver emails to the real world.
30
+ # The :test delivery method accumulates sent emails in the
31
+ # ActionMailer::Base.deliveries array.
32
+ config.action_mailer.delivery_method = :test
33
+
34
+ # Randomize the order test cases are executed.
35
+ config.active_support.test_order = :random
36
+
37
+ # Print deprecation notices to the stderr.
38
+ config.active_support.deprecation = :stderr
39
+
40
+ # Raises error for missing translations
41
+ # config.action_view.raise_on_missing_translations = true
42
+ end
@@ -0,0 +1,142 @@
1
+ #
2
+ # Advanced Connection Configuration
3
+ #
4
+ AdvancedConnection.configure do |config|
5
+ #
6
+ ## Idle Manager
7
+ #
8
+ # Enabling this will enable idle connection management. This allows you to specify settings
9
+ # to enable automatic warmup of connections on rails startup, min/max idle connections and
10
+ # idle connection culling.
11
+ #
12
+ config.enable_idle_connection_manager = true
13
+
14
+ # Pool queue type determines both how free connections will be checkout out
15
+ # of the pool, as well as how idle connections will be culled. The options are:
16
+ #
17
+ # :fifo - All connections will have an equal opportunity to be used and culled (default)
18
+ # :lifo/:stack - More frequently used connections will be reused, leaving less frequently used
19
+ # connections to be culled
20
+ # :prefer_older - Longer lived connections will tend to stick around longer, with younger
21
+ # connections being culled
22
+ # :prefer_younger - Younger lived connections will tend to stick around longer, with older
23
+ # connections being culled
24
+ #
25
+ config.connection_pool_queue_type = :prefer_older
26
+
27
+ # How many connections to prestart on initial startup of rails. This can
28
+ # help to reduce the time it takes a restarted production node to start
29
+ # responding again.
30
+ #
31
+ config.warmup_connections = 10
32
+
33
+ # Minimum number of connection to keep idle. If, during the idle check, you have fewer
34
+ # than this many connections idle, then a number of new connections will be created
35
+ # up to this this number.
36
+ #
37
+ config.min_idle_connections = 5
38
+
39
+ # Maximum number of connections that can remain idle without being culled. If you have
40
+ # more idle conections than this, only the difference between the total idle and this
41
+ # maximum will be culled.
42
+ #
43
+ config.max_idle_connections = 5
44
+
45
+ # How long (in seconds) a connection can remain idle before being culled
46
+ #
47
+ config.max_idle_time = 90
48
+
49
+ # How many seconds between idle checks (defaults to max_idle_time)
50
+ #
51
+ config.idle_check_interval = 30
52
+
53
+ #
54
+ ## Without Connection
55
+ #
56
+ # Enabling this will add a new method to ActiveRecord::Base that allows you to
57
+ # mark a block of code as not requiring a connection. This can be useful in reducing
58
+ # pressure on the pool, especially when you have sections of code that make
59
+ # potentially long-lived external requests. E.g.,
60
+ #
61
+ # require 'open-uri'
62
+ # results = ActiveRecord::Base.without_connection do
63
+ # open('http://some-slow-site.com/api/foo')
64
+ # end
65
+ #
66
+ # During the call to the remote site, the db connection is checked in and subsequently
67
+ # checked back out once the block finishes.
68
+ #
69
+ # To enable this feature, uncomment the following:
70
+ #
71
+ config.enable_without_connection = true
72
+ #
73
+ # WARNING: this feature cannot be enabled with Statement Pooling.
74
+ #
75
+ # Additionally, you can hook into the checkin / chekcout lifecycle by way of callbacks. This
76
+ # can be extremely useful when employing something like Apartment to manage switching
77
+ # between tenants.
78
+ #
79
+ config.without_connection_callbacks = {
80
+ # runs right before the connection is checked back into the pool
81
+ around: ->(&block) {
82
+ $stderr.puts "storing tenant"
83
+ #tenant = Apartment::Tenant.current
84
+ block.call
85
+ $stderr.puts "restoring tenant"
86
+ #Apartment::Tenant.switch!(tenant)
87
+ },
88
+ }
89
+ #
90
+ ## Statement Pooling
91
+ #
92
+ # **** WARNING **** EXPERIMENTAL **** WARNING **** EXPERIMENTAL ****
93
+ #
94
+ # THIS FEATURE IS HIGHLY EXPERIMENTAL AND PRONE TO FAILURE. DO NOT USE UNLESS
95
+ # YOU PLAN TO AIDE IN IT'S DEVELOPMENT.
96
+ #
97
+ # When enabled, this feature causes your connections to immediately be returned to
98
+ # the pool upon completion of each query (with the exception of transactions, where
99
+ # the connection is returned after transaction commit/rollback). This can help to
100
+ # reduce pressure on the pool, as well as the number of the connections to the
101
+ # backend by making more efficient use of existing connections.
102
+ #
103
+ # WARNING: this cannot be enabled with Without Connection.
104
+ #
105
+ # To enable, simply uncomment the following:
106
+ #
107
+ # config.enable_statement_pooling = true
108
+ #
109
+ # Additionally, callbacks are provided around the connection checkin. This can
110
+ # be extremely useful when in a multi-tenant situation using something like
111
+ # Apartment, e.g.:
112
+ #
113
+ # lib/apartment/elevators/my_elevator.rb:
114
+ # module Apartment::Elevators
115
+ # class MyElevator < Generic
116
+ # def call(env)
117
+ # super
118
+ # ensure
119
+ # Thread.current[:tenant] = nil
120
+ # Apartment::Tenant.reset
121
+ # end
122
+ #
123
+ # def parse_tenant_name(request)
124
+ # request.host.split('.').first.tap do |tenant|
125
+ # Thread.current[:tenant] = tenant
126
+ # end
127
+ # end
128
+ # end
129
+ # . . .
130
+ # end
131
+ #
132
+ # and then set your statement_pooling_callbacks like so:
133
+ #
134
+ # config.statement_pooling_callbacks = {
135
+ # # switch back to the stored tenant prior to executing sql
136
+ # before: ->() {
137
+ # if Thread.current[:tenant]
138
+ # Apartment::Tenant.switch(Thread.current[:tenant])
139
+ # end
140
+ # }
141
+ # }
142
+ end