Class: Scryer::PerformanceRules::MissingPaginationRule

Inherits:
Rule
  • Object
show all
Defined in:
lib/scryer/performance_rules/missing_pagination_rule.rb

Overview

Flags a controller index action that loads Model.all or a bare Model.where(...) (no .limit/.page/.per/.paginate/.find_each bound anywhere in the chain) and hands the result straight to an instance variable or render — i.e. nothing bounds how many rows get loaded and rendered. Heuristic: only looks at the literal call chain text, not what happens to the variable afterwards (e.g. slicing it in the view would not be detected as "safe" by this rule).

Constant Summary collapse

QUERY_METHODS =
%w[all where].freeze
BOUND_METHODS =
%w[limit page per paginate find_each find_in_batches first take].freeze

Instance Attribute Summary

Attributes inherited from Rule

#file, #sexp, #source

Instance Method Summary collapse

Methods inherited from Rule

inherited, #initialize

Constructor Details

This class inherits a constructor from Scryer::Rule

Instance Method Details

#scanObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/scryer/performance_rules/missing_pagination_rule.rb', line 19

def scan
  findings = []

  Ast.each_node(sexp) do |node|
    next unless Ast.tagged?(node, :def)
    next unless Ast.ident_text(node[1]) == "index"

    body = node.last
    findings.concat(check_body(body))
  end

  findings
end