|
1 | 1 | /** |
2 | | - * @name Could be async |
3 | | - * @description Use `ActiveRecord::Relation#load_async` to load records asynchronously. |
| 2 | + * @name Could be hoisted |
| 3 | + * @description Hoist Rails `ActiveRecord::Relation` query calls out of loops. |
4 | 4 | * @kind problem |
5 | 5 | * @problem.severity info |
6 | 6 | * @precision high |
7 | | - * @id rb/could-be-async |
| 7 | + * @id rb/could-be-hoisted |
8 | 8 | * @tags performance |
9 | 9 | */ |
10 | 10 |
|
@@ -82,18 +82,14 @@ DataFlow::Node guardForLoopControl(ConditionalExpr cond, Stmt control) { |
82 | 82 | control = cond.getBranch(_).getAChild() |
83 | 83 | } |
84 | 84 |
|
85 | | -from LoopingCall loop, DataFlow::CallNode call, string message |
| 85 | +from LoopingCall loop, DataFlow::CallNode call |
86 | 86 | where |
| 87 | + // TODO: Filter loops over constants |
87 | 88 | not call.getLocation().getFile().getAbsolutePath().matches("%test%") and |
88 | | - not call = any(PluckCall p).chaines() and |
| 89 | + // not call = any(PluckCall p).chaines() and |
89 | 90 | not usedInLoopControlGuard(call, _) and |
90 | 91 | happensInInnermostLoop(loop, call) and |
91 | | - ( |
92 | | - call instanceof ActiveRecordModelFinderCall and |
93 | | - not call.getMethodName() in ["new", "create"] and |
94 | | - message = "could be chained with load_async" |
95 | | - or |
96 | | - call instanceof PluckCall and |
97 | | - message = "could be async_pluck" |
98 | | - ) |
99 | | -select call, "This call happens inside $@, and " + message, loop, "this loop" |
| 92 | + call instanceof ActiveRecordModelFinderCall and |
| 93 | + not call.getMethodName() in ["new", "create"] //and |
| 94 | +// call.getLocation().getFile().getAbsolutePath().matches("%app/models/stafftools/%") |
| 95 | +select call, "This call happens inside $@, and could be hoisted.", loop, "this loop" |
0 commit comments