Optimize user logins by avoiding duplicate entity queries

Created on 22 December 2023, about 2 years ago
Updated 25 June 2024, over 1 year ago

Problem/Motivation

In UserLoginForm, first we check if the user name matches a blocked user via an entity query.

Then we check if the user name matches a not-blocked user before checking flood control by username, via another entity query.

Once the user has passed flood control, we then call UserAuth::authenticate() with the username and password - this runs the second entity query again to locate the user by username that we've already done.

Steps to reproduce

Watch database queries (via Drupal's performance testing framework + Gander or just have a look at the test coverage changes.

Proposed resolution

Add UserAuth::authenticateAccount($account, $password) to save looking up the user twice, then use it in UserLoginForm.

Because the authentication validator checks if users are active (and exist) before trying to authenticate them, we only need to check if they're blocked if they fail to validate to show a different validation message. IMO this validation message is a bit questionable, but trying to keep functionality the same.

This is stacked on 📌 Only clear flood attempts when necessary during user login RTBC due to affecting the same lines of test coverage, but the fixes are independent otherwise.

If the login fails, fallback to checking if the user is blocked to maintain the same message in that case.

Deprecate User::validateName()

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

📌 Task
Status

Fixed

Version

10.3

Component
User module 

Last updated 2 months ago

Created by

🇬🇧United Kingdom catch

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024