Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/query_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def search_filter(column_maps)
raise ArgumentError.new("search_fields not defined") unless @search_fields.length > 0
placement = :where
maps = column_maps.select do |cm|
if @search_fields.include? cm.alias_name
if @search_fields.map(&:downcase).include? cm.alias_name.downcase
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation has a performance issue: the @search_fields.map(&:downcase) array is created on every iteration of the select block, once for each column_map. This should be computed once before the select block. Additionally, the case-insensitive comparison approach is inconsistent with the codebase - sql_sort.rb uses casecmp? for alias matching (line 37 in sql_sort.rb), which is the idiomatic Ruby approach. Consider refactoring to: downcased_search_fields = @search_fields.map(&:downcase) before the select, then use downcased_search_fields.include?(cm.alias_name.downcase), or better yet, use @search_fields.any? { |sf| sf.casecmp?(cm.alias_name) } for consistency with sql_sort.rb.

Suggested change
if @search_fields.map(&:downcase).include? cm.alias_name.downcase
if @search_fields.any? { |sf| sf.casecmp?(cm.alias_name) }

Copilot uses AI. Check for mistakes.
placement = :having if cm.aggregate
true
else
Expand Down
2 changes: 1 addition & 1 deletion lib/query_helper/sql_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create_filters

@filter_values.each do |comparate_alias, criteria|
# Find the sql mapping if it exists
map = @column_maps.find { |m| m.alias_name == comparate_alias }
map = @column_maps.find { |m| m.alias_name.downcase == comparate_alias.downcase }
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The case-insensitive comparison approach here is inconsistent with the codebase. The sql_sort.rb file uses the casecmp? method for case-insensitive alias matching (line 37 in sql_sort.rb), which is the idiomatic Ruby approach. Using casecmp? would be more consistent, more readable, and doesn't create intermediate string objects. Consider changing this to: map = @column_maps.find { |m| m.alias_name.casecmp?(comparate_alias) }

Suggested change
map = @column_maps.find { |m| m.alias_name.downcase == comparate_alias.downcase }
map = @column_maps.find { |m| m.alias_name.casecmp?(comparate_alias) }

Copilot uses AI. Check for mistakes.
raise InvalidQueryError.new("cannot filter by #{comparate_alias}") unless map

# create the filter
Expand Down
Loading