Performance issues with BasicAuth and LoginAttempts

Two functions interact with the LoginAttempt object which when used in conjunction with BasicAuth result in significant performance degradation over time, as the LoginAttempts Table fills.

This fix adds an index to the lookup column EmailHashed and removes the Email filter part of getByEmail() so it can use the index resulting in a much faster query.

For more information see https://github.com/silverstripe/silverstripe-framework/issues/8389
This commit is contained in:
Simon Gow 2018-09-19 14:53:12 +12:00
parent 270aba4007
commit c269a987d5

View File

@ -46,6 +46,10 @@ class LoginAttempt extends DataObject
'Member' => Member::class, // only linked if the member actually exists
);
private static $indexes = array(
"EmailHashed" => true
);
private static $table_name = "LoginAttempt";
/**
@ -86,7 +90,6 @@ class LoginAttempt extends DataObject
public static function getByEmail($email)
{
return static::get()->filterAny(array(
'Email' => $email,
'EmailHashed' => sha1($email),
));
}