Do not load every single key when checking for a match during authentication

Created on 6 April 2018, about 6 years ago
Updated 22 March 2024, 3 months ago

Loading every single key in order to check for a key match does not make much sense when you can simply add a condition to the query.

Before:

$api_key_entities = \Drupal::entityTypeManager()
      ->getStorage('api_key')
      ->loadMultiple();
    foreach ($api_key_entities as $key_item) {

      if ($this->getKey($request) == $key_item->key) {

After:

$key = $this->entityTypeManager
  ->getStorage('api_key')
  ->getQuery()
  ->condition('key', $this->getKey($request))
  ->execute();
πŸ“Œ Task
Status

Closed: outdated

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States mstef

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    This has been fixed in the meantime, I guess?

    The current code looks like this:

    // Load config entity.
        $api_key_entities = \Drupal::entityTypeManager()
          ->getStorage('api_key')
          ->loadByProperties(['key' => $this->getKey($request)]);
    
Production build 0.69.0 2024