Skip to content

Commit

Permalink
Merge pull request #15 from pocke/Avoid_modifying_unnecessary_nodes
Browse files Browse the repository at this point in the history
Avoid modifying unnecessary nodes for performance
  • Loading branch information
pocke committed Mar 16, 2024
2 parents 827aff1 + 16543ab commit 7c32d29
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
8 changes: 7 additions & 1 deletion lib/activerecord/originator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
require_relative "originator/arel_visitor_extension"
require_relative "originator/collector_proxy"

Arel::Nodes::Node.descendants.each do |klass|
ActiveRecord::Originator::ArelVisitorExtension::TARGET_NODE_CLASSESS.each do |name|
begin
klass = Arel::Nodes.const_get(name)
rescue NameError
# Some classes are not defined in old arel
next
end
klass.prepend ActiveRecord::Originator::ArelNodeExtension
end
Arel::Visitors::ToSql.prepend ActiveRecord::Originator::ArelVisitorExtension
Expand Down
18 changes: 10 additions & 8 deletions lib/activerecord/originator/arel_visitor_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
module ActiveRecord
module Originator
module ArelVisitorExtension
def accept(object, collector)
super(object, CollectorProxy.new(collector))
end

private

%i[
TARGET_NODE_CLASSESS = %i[
Ascending
Descending
Equality
Expand All @@ -21,7 +15,15 @@ def accept(object, collector)
LessThan
LessThanOrEqual
GreaterThanOrEqual
].each do |klass_name|
]

def accept(object, collector)
super(object, CollectorProxy.new(collector))
end

private

TARGET_NODE_CLASSESS.each do |klass_name|
define_method(:"visit_Arel_Nodes_#{klass_name}") do |o, collector|
__skip__ = begin
comment = originator_comment(o)
Expand Down
1 change: 1 addition & 0 deletions sig/activerecord/originator/arel_visitor_extension.rbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module ActiveRecord
module Originator
module ArelVisitorExtension : _ArelVisitor
TARGET_NODE_CLASSESS: Array[Symbol]
def accept: (untyped object, _Collector collector) -> untyped

private
Expand Down

0 comments on commit 7c32d29

Please sign in to comment.