From c39a1022cc9de539ec6ac4f46a6bf39356e9bcda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 22 Oct 2018 11:14:13 +0200 Subject: [PATCH] PERF: user imports would slow down the more users were imported --- script/import_scripts/base.rb | 3 ++- script/import_scripts/base/lookup_container.rb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/script/import_scripts/base.rb b/script/import_scripts/base.rb index ead0601395c..367236092f5 100644 --- a/script/import_scripts/base.rb +++ b/script/import_scripts/base.rb @@ -390,7 +390,8 @@ class ImportScripts::Base end 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 def created_category(category) diff --git a/script/import_scripts/base/lookup_container.rb b/script/import_scripts/base/lookup_container.rb index 2e6f2c0af21..fa324db0519 100644 --- a/script/import_scripts/base/lookup_container.rb +++ b/script/import_scripts/base/lookup_container.rb @@ -37,7 +37,7 @@ module ImportScripts # Get the Discourse Group id based on the id of the source group 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 # 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 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 # Get the Discourse User based on the id of the source user