aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/explain_registry.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/explain_registry.rb')
-rw-r--r--activerecord/lib/active_record/explain_registry.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/explain_registry.rb b/activerecord/lib/active_record/explain_registry.rb
new file mode 100644
index 0000000000..7fd078941a
--- /dev/null
+++ b/activerecord/lib/active_record/explain_registry.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+require "active_support/per_thread_registry"
+
+module ActiveRecord
+ # This is a thread locals registry for EXPLAIN. For example
+ #
+ # ActiveRecord::ExplainRegistry.queries
+ #
+ # returns the collected queries local to the current thread.
+ #
+ # See the documentation of ActiveSupport::PerThreadRegistry
+ # for further details.
+ class ExplainRegistry # :nodoc:
+ extend ActiveSupport::PerThreadRegistry
+
+ attr_accessor :queries, :collect
+
+ def initialize
+ reset
+ end
+
+ def collect?
+ @collect
+ end
+
+ def reset
+ @collect = false
+ @queries = []
+ end
+ end
+end