PERF: user imports would slow down the more users were imported

This commit is contained in:
Régis Hanol 2018-10-22 11:14:13 +02:00
parent afa22a0c6f
commit c39a1022cc
2 changed files with 4 additions and 3 deletions

View File

@ -390,7 +390,8 @@ class ImportScripts::Base
end end
def find_existing_user(email, username) def find_existing_user(email, username)
User.joins(:user_emails).where("user_emails.email = ? OR username = ?", email.downcase, username).first # Force the use of the index on the 'user_emails' table
UserEmail.where("lower(email) = ?", email.downcase).first&.user || User.where(username: username).first
end end
def created_category(category) def created_category(category)

View File

@ -37,7 +37,7 @@ module ImportScripts
# Get the Discourse Group id based on the id of the source group # Get the Discourse Group id based on the id of the source group
def group_id_from_imported_group_id(import_id) def group_id_from_imported_group_id(import_id)
@groups[import_id] || @groups[import_id.to_s] || find_group_by_import_id(import_id).try(:id) @groups[import_id] || @groups[import_id.to_s]
end end
# Get the Discourse Group based on the id of the source group # Get the Discourse Group based on the id of the source group
@ -47,7 +47,7 @@ module ImportScripts
# Get the Discourse User id based on the id of the source user # Get the Discourse User id based on the id of the source user
def user_id_from_imported_user_id(import_id) def user_id_from_imported_user_id(import_id)
@users[import_id] || @users[import_id.to_s] || find_user_by_import_id(import_id).try(:id) @users[import_id] || @users[import_id.to_s]
end end
# Get the Discourse User based on the id of the source user # Get the Discourse User based on the id of the source user