class THTP::Server::Middleware::ActiveRecordPool

Performs explicit rather than implicit AR connection management to ensure we don't run out of SQL connections. Note that this approach is suboptimal from a contention standpoint (better to check out once per thread), but that sync time should be irrelevant if we size our pool correctly, which we do. It is also suboptimal if we have any handler methods that do not hit the database at all, but that's unlikely.

For more details, check out (get it?): bibwild.wordpress.com/2014/07/17/activerecord-concurrency-in-rails4-avoid-leaked-connections/

This is probably only useful on servers.

Public Class Methods

new(app) click to toggle source
# File lib/thtp/server/middleware.rb, line 38
def initialize(app)
  require 'active_record' # if you don't have it, why do you want this?
  @app = app
end

Public Instance Methods

call(rpc, *rpc_args_and_opts) click to toggle source
# File lib/thtp/server/middleware.rb, line 43
def call(rpc, *rpc_args_and_opts)
  ActiveRecord::Base.connection_pool.with_connection { @app.call(rpc, *rpc_args_and_opts) }
end