Class: PgCanary::Rules::SelectStarWithHeavyColumns
- Defined in:
- lib/pg_canary/rules/definitions/select_star_with_heavy_columns.rb
Overview
SELECT * (ActiveRecord's default) on a table that has heavy columns (bytea / text / jsonb) transfers those payloads on every query. Whether that matters depends on the data, hence opt-in. Heavy types: config.rules.select_star_with_heavy_columns.heavy_types.
Instance Method Summary collapse
Methods inherited from Base
all, check, default_enabled, enabled?, #initialize, option, options, rule_name
Constructor Details
This class inherits a constructor from PgCanary::Rules::Base
Instance Method Details
#check ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/pg_canary/rules/definitions/select_star_with_heavy_columns.rb', line 15 def check heavy_types = rule_config.heavy_types detections = [] each_scope do |scope| star_tables(scope).each do |table| next unless applicable_table?(table) heavy = column_types(table).select { |_, type| heavy_types.include?(type) }.keys next if heavy.empty? detections << detection( table: table, columns: heavy, message: "SELECT * on #{table} transfers its heavy columns (#{heavy.join(", ")}) " \ "on every query.", suggestion: "Select only the columns you need (.select(:id, ...)), or move large " \ "payloads to a separate table loaded on demand." ) end end detections end |