Skip to content

Commit 501a140

Browse files
authored
Remove superfluous case normalization logic in App/User (#1049)
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
1 parent 85b46f9 commit 501a140

3 files changed

Lines changed: 2 additions & 6 deletions

File tree

app/Console/Commands/User/CheckUserEmailExist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function handle(WikiUserEmailChecker $emailChecker): int {
1616
foreach ($emails as $email) {
1717
$found = false;
1818

19-
if (User::whereEmailInsensitive($email)->exists()) {
19+
if (User::whereEmail($email)->exists()) {
2020
$this->line("FOUND: {$email} in apidb.users");
2121
$found = true;
2222
}

app/User.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,4 @@ public function sendEmailVerificationNotification() {
121121
public function getEmailForVerification() {
122122
return $this->email;
123123
}
124-
125-
public function scopeWhereEmailInsensitive($query, string $email) {
126-
return $query->whereRaw('LOWER(email) = ?', [strtolower($email)]);
127-
}
128124
}

tests/Commands/User/CheckUserEmailExistTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testCaseInsensitive() {
6060
'email' => 'Test@Example.com',
6161
]);
6262

63-
$exists = User::whereEmailInsensitive('tEsT@eXaMpLe.CoM')->exists();
63+
$exists = User::whereEmail('tEsT@eXaMpLe.CoM')->exists();
6464

6565
$this->assertTrue($exists);
6666
}

0 commit comments

Comments
 (0)