-
Notifications
You must be signed in to change notification settings - Fork 21.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created a runtime registry for thread local variables in active record.
- Loading branch information
Showing
5 changed files
with
39 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,32 @@ | |||
require 'active_support/per_thread_registry' | |||
|
|||
module ActiveRecord | |||
# This is a registry class for storing local variables in active record. The | |||
# class allows you to access variables that are local to the current thread. | |||
# These thread local variables are stored as attributes in the | |||
# +RuntimeRegistry+ class. | |||
# | |||
# You can access the thread local variables by calling a variable's name on | |||
# the +RuntimeRegistry+ class. For example, if you wanted to obtain the | |||
# connection handler for the current thread, you would invoke: | |||
# | |||
# ActiveRecord::RuntimeRegistry.instance.connection_handler | |||
# | |||
# The +PerThreadRegistry+ module will make a new +RuntimeRegistry+ instance | |||
# and store it in +Thread.current+. Whenever you make a call for an attribute | |||
# on the +RuntimeRegistry+ class, the call will be sent to the instance that | |||
# is stored in +Thread.current+. | |||
# | |||
# Note that you can also make the following call which would provide an | |||
# equivalent result as the previous code: | |||
# | |||
# ActiveRecord::RuntimeRegistry.connection_handler | |||
# | |||
# However, this is less performant because it makes a call to +method_missing+ | |||
# before it sends the method call to the +instance+. | |||
class RuntimeRegistry | |||
extend ActiveSupport::PerThreadRegistry | |||
|
|||
attr_accessor :connection_handler, :sql_runtime, :connection_id | |||
end | |||
end |