From 9fdc49dabad773a866fc081af024cf1420740684 Mon Sep 17 00:00:00 2001 From: Ollie Date: Tue, 27 Jan 2026 10:35:51 +0000 Subject: [PATCH] Remove superfluous case normalization logic in App/User The Laravel email column is a `varchar(255)` with a `utf8mb4_unicode_ci` collation[1] which is case-insensitive. No further case normalization is required, and doing so will slow down the search. Also, `strtolower()` only converts ASCII alphabetic characters[2]. `mb_strtolower()` is required to convert non-ASCII character as well. [1]: https://mariadb.com/docs/server/reference/data-types/string-data-types/character-sets/supported-character-sets-and-collations [2]: https://www.php.net/manual/en/function.strtolower.php Bug: T415640 --- app/Console/Commands/User/CheckUserEmailExist.php | 2 +- app/User.php | 4 ---- tests/Commands/User/CheckUserEmailExistTest.php | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/app/Console/Commands/User/CheckUserEmailExist.php b/app/Console/Commands/User/CheckUserEmailExist.php index 859edd77..5b33f180 100644 --- a/app/Console/Commands/User/CheckUserEmailExist.php +++ b/app/Console/Commands/User/CheckUserEmailExist.php @@ -16,7 +16,7 @@ public function handle(WikiUserEmailChecker $emailChecker): int { foreach ($emails as $email) { $found = false; - if (User::whereEmailInsensitive($email)->exists()) { + if (User::whereEmail($email)->exists()) { $this->line("FOUND: {$email} in apidb.users"); $found = true; } diff --git a/app/User.php b/app/User.php index e809eed8..45459e71 100644 --- a/app/User.php +++ b/app/User.php @@ -121,8 +121,4 @@ public function sendEmailVerificationNotification() { public function getEmailForVerification() { return $this->email; } - - public function scopeWhereEmailInsensitive($query, string $email) { - return $query->whereRaw('LOWER(email) = ?', [strtolower($email)]); - } } diff --git a/tests/Commands/User/CheckUserEmailExistTest.php b/tests/Commands/User/CheckUserEmailExistTest.php index 98dfd20d..e91f1f61 100644 --- a/tests/Commands/User/CheckUserEmailExistTest.php +++ b/tests/Commands/User/CheckUserEmailExistTest.php @@ -61,7 +61,7 @@ public function testCaseInsensitive() { 'email' => 'Test@Example.com', ]); - $exists = User::whereEmailInsensitive('tEsT@eXaMpLe.CoM')->exists(); + $exists = User::whereEmail('tEsT@eXaMpLe.CoM')->exists(); $this->assertTrue($exists); }