diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2015-10-08 13:28:26 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2015-10-15 11:58:25 +0200 |
commit | 72f428c7d217a5c40ed87d68ab9100e4c8754633 (patch) | |
tree | 6462eeb047a35216e6131ca73b76551b1e9d6725 /db | |
parent | fb7785628a04f9facb0d05867cb5c4cafb646561 (diff) | |
download | gitlab-ce-72f428c7d217a5c40ed87d68ab9100e4c8754633.tar.gz |
Improve performance of User.by_loginuser-by-login-performance
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 'db')
-rw-r--r-- | db/migrate/20151008110232_add_users_lower_username_email_indexes.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/db/migrate/20151008110232_add_users_lower_username_email_indexes.rb b/db/migrate/20151008110232_add_users_lower_username_email_indexes.rb new file mode 100644 index 00000000000..2f2dc776785 --- /dev/null +++ b/db/migrate/20151008110232_add_users_lower_username_email_indexes.rb @@ -0,0 +1,17 @@ +class AddUsersLowerUsernameEmailIndexes < ActiveRecord::Migration + disable_ddl_transaction! + + def up + return unless Gitlab::Database.postgresql? + + execute 'CREATE INDEX CONCURRENTLY index_on_users_lower_username ON users (LOWER(username));' + execute 'CREATE INDEX CONCURRENTLY index_on_users_lower_email ON users (LOWER(email));' + end + + def down + return unless Gitlab::Database.postgresql? + + remove_index :users, :index_on_users_lower_username + remove_index :users, :index_on_users_lower_email + end +end |