diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2015-10-08 14:28:26 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2015-10-15 12:58:25 +0300 |
commit | 72f428c7d217a5c40ed87d68ab9100e4c8754633 (patch) | |
tree | 6462eeb047a35216e6131ca73b76551b1e9d6725 /spec/benchmarks | |
parent | fb7785628a04f9facb0d05867cb5c4cafb646561 (diff) |
Improve performance of User.by_login
Performance is improved in two steps:
1. On PostgreSQL an expression index is used for checking lower(email)
and lower(username).
2. The check to determine if we're searching for a username or Email is
moved to Ruby. Thanks to @haynes for suggesting and writing the
initial implementation of this.
Moving the check to Ruby makes this method an additional 1.5 times
faster compared to doing the check in the SQL query.
With performance being improved I've now also tweaked the amount of
iterations required by the User.by_login benchmark. This method now runs
between 900 and 1000 iterations per second.
Diffstat (limited to 'spec/benchmarks')
-rw-r--r-- | spec/benchmarks/models/user_spec.rb | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/spec/benchmarks/models/user_spec.rb b/spec/benchmarks/models/user_spec.rb index 168be20b7a5..cc5c3904193 100644 --- a/spec/benchmarks/models/user_spec.rb +++ b/spec/benchmarks/models/user_spec.rb @@ -11,7 +11,9 @@ describe User, benchmark: true do end end - let(:iterations) { 1000 } + # The iteration count is based on the query taking little over 1 ms when + # using PostgreSQL. + let(:iterations) { 900 } describe 'using a capitalized username' do benchmark_subject { User.by_login('Alice') } |