ITADN

Add withoutDetection() method for suppressing N+1 detection

#116Pull Requestdingyaguang117 创建于 2026-02-13
D
dingyaguang117commented
## Motivation The existing except config requires whitelisting by model + relation pair, which is too coarse-grained. In practice, developers often need to suppress detection for a specific code block (e.g. admin pages with small datasets, legacy endpoints, or background jobs) rather than globally whitelisting a relation. ## What I did - Add QueryDetector::withoutDetection(callable $callback) method that temporarily disables N+1 detection for the duration of the closure - Uses a simple $disabled flag — no reflection or backtrace scanning overhead - The closure's return value is passed through - Detection resumes automatically after the closure, even if it throws an exception ## Usage ``` app(QueryDetector::class)->withoutDetection(function () { // N+1 queries here will not be reported foreach (Author::all() as $author) { $author->posts; } }); ```
合并状态:未合并 1 条评论