Skip to content

Commit

Permalink
Use quoted table name
Browse files Browse the repository at this point in the history
Retrieving quoted table name directly from the class instead of
re-calculating it from the connection is an order of magnitude faster

```rb
class User < ActiveRecord::Base
  def self.qtn
    quoted_table_name
  end

  def self.cqtn
    connection.quote_table_name(table_name)
  end
end
```

Ruby 2.2 / Rails 5.0:
```
            User.qtn:  3003860.8 i/s
           User.cqtn:   259818.5 i/s - 11.56x  slower
```

Ruby 3.2 / Rails 7.0:

```
Comparison:
            User.qtn: 13504395.2 i/s
           User.cqtn:   517189.1 i/s - 26.11x  slower
```
  • Loading branch information
tagliala committed Sep 22, 2023
1 parent dfddf74 commit 4c6ca4f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/chrono_model/time_machine/timeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def timeline_associations_from(names)

def quoted_history_fields
@quoted_history_fields ||= begin
validity = "#{connection.quote_table_name(table_name)}.#{connection.quote_column_name('validity')}"
validity = "#{quoted_table_name}.#{connection.quote_column_name('validity')}"

%w[lower upper].map! { |func| "#{func}(#{validity})" }
end
Expand Down

0 comments on commit 4c6ca4f

Please sign in to comment.