pub struct N1DetectionScope { /* private fields */ }Expand description
Scope helper for N+1 detection tracking.
This helper captures the initial N+1 stats when created, allowing you to compare against final stats and log a summary of issues detected within the scope.
Note: This is NOT an automatic RAII guard - you must call log_summary()
manually with the final stats. For automatic logging, wrap your code in a
block and call log_summary at the end.
§Example
// Capture initial state
let scope = N1DetectionScope::from_tracker(session.n1_tracker());
// Do work that might cause N+1...
for hero in &mut heroes {
hero.team.load(&mut session).await?;
}
// Manually log summary with final stats
scope.log_summary(&session.n1_stats());Implementations§
Source§impl N1DetectionScope
impl N1DetectionScope
Sourcepub fn new(initial_stats: N1Stats, threshold: usize) -> Self
pub fn new(initial_stats: N1Stats, threshold: usize) -> Self
Create a new detection scope.
This does NOT automatically enable detection on a Session - the caller
should have already called session.enable_n1_detection(). This scope
captures the initial state and logs a summary on drop.
§Arguments
initial_stats- The current N1Stats (fromsession.n1_stats())threshold- The threshold being used for detection
Sourcepub fn from_tracker(tracker: &N1QueryTracker) -> Self
pub fn from_tracker(tracker: &N1QueryTracker) -> Self
Create a scope from a tracker reference.
Convenience method that extracts stats and threshold from an existing tracker.
Sourcepub fn log_summary(&self, final_stats: &N1Stats)
pub fn log_summary(&self, final_stats: &N1Stats)
Log a summary of the detection results.
Called automatically on drop, but can be called manually for intermediate reporting.