Module: Immunio::StatementCacheHooks
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/immunio/plugins/active_record_relation.rb
Overview
Some simple queries, specifically #find and #find_by with simple conditions may be saved in a statement cache so the statement doesn’t need to be built from an AST every time. When a query is executed from the cache, the cached query statement is executed without going through any of the wrapped ActiveRecord::Relation methods. We wrap the execution to ensure we push the original relation for the cached statement onto the connection relation stack.
Note: Because cached statements won’t build up the query from an AST, we won’t have AST context data. That should be ok because only the simplest queries are cacheable, queries that won’t vary in structure even for the same stack trace and relation API calls.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#execute_with_immunio(*args, &block) ⇒ Object
When a statement is executed, push the original relation onto the connection relation stack.
Instance Method Details
#execute_with_immunio(*args, &block) ⇒ Object
When a statement is executed, push the original relation onto the connection relation stack.
273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/immunio/plugins/active_record_relation.rb', line 273 def execute_with_immunio(*args, &block) Request.time "plugin", "Immunio::RelationTracking" do QueryTracker.instance.push_relation @__immunio_relation end begin execute_without_immunio(*args, &block) ensure Request.time "plugin", "Immunio::RelationTracking" do QueryTracker.instance.pop_relation @__immunio_relation end end end |