Skip to content

Instantly share code, notes, and snippets.

@thbar
Created June 22, 2009 08:03
Show Gist options
  • Save thbar/133857 to your computer and use it in GitHub Desktop.
Save thbar/133857 to your computer and use it in GitHub Desktop.
# patch to handle connection pooling outside of rails: http://www.williambharding.com/blog/rants/rails-22-connection-pools-mongrel-handlers-bloodbath/
# call ActiveRecord::Base.connection_handler.clear_connection! from your controller once you're done with ActiveRecord work
module ActiveRecord
module ConnectionAdapters
class ConnectionPool
def release_connection(conn_id = nil)
conn_id ||= current_connection_id
conn = @reserved_connections.delete(conn_id)
checkin conn if conn
end
end
class ConnectionHandler
def clear_connection!
@connection_pools.each_value {|pool| pool.release_connection(Thread.current.object_id) }
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment