Skip to content

Commit

Permalink
Avoid shape-related performance warning for Sequel::SQL::StringAgg
Browse files Browse the repository at this point in the history
Making the order the same helps.  This does define an unnecessary
instance variable, but it makes the order consistent.  This keeps
the object to 2 shapes (one without @order_expr and @distinct,
and one with both).
  • Loading branch information
jeremyevans committed Dec 13, 2024
1 parent 0242c40 commit 7a520bb
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/sequel/extensions/string_agg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,16 @@ def is_distinct?
# Return a modified StringAgg that uses distinct expressions
def distinct
self.class.new(@expr, @separator) do |sa|
sa.instance_variable_set(:@order_expr, @order_expr) if @order_expr
sa.instance_variable_set(:@order_expr, @order_expr)
sa.instance_variable_set(:@distinct, true)
end
end

# Return a modified StringAgg with the given order
def order(*o)
self.class.new(@expr, @separator) do |sa|
sa.instance_variable_set(:@distinct, @distinct) if @distinct
sa.instance_variable_set(:@order_expr, o.empty? ? nil : o.freeze)
sa.instance_variable_set(:@distinct, @distinct)
end
end

Expand Down

0 comments on commit 7a520bb

Please sign in to comment.