More concise Arel `Or` ast and make `Or` visitor non recursive
Before this, 1000 `Or` nodes will raise "stack level too deep" due to visiting too deep Arel ast. This makes more concise Arel `Or` ast and `Or` visitor non recursive if `Or` nodes are adjoined, as a result, "stack level too deep" is no longer raised. ```ruby class Post < ActiveRecord::Base end posts = (0..500).map { |i| Post.where(id: i) } Benchmark.ips do |x| x.report("inject scopes") { posts.inject(&:or).to_sql } end ``` Before: ``` Warming up -------------------------------------- where with ids 9.000 i/100ms Calculating ------------------------------------- where with ids 96.126 (± 2.1%) i/s - 486.000 in 5.058960s ``` After: ``` Warming up -------------------------------------- inject scopes 10.000 i/100ms Calculating ------------------------------------- inject scopes 101.714 (± 2.9%) i/s - 510.000 in 5.018880s ``` Fixes #39032.
Showing
想要评论请 注册 或 登录