Problem/Motivation

Currently, null data is cached if a wrong username is given.

Steps to reproduce

Enter a wrong username. The field would still save the data and cache the data with null.

Proposed resolution

Set the cache only if the data exists.

  public function getUserInformation(string $doUsername): User {
    $cid = 'do_username:user:' . $doUsername;

    // Check if the data exist. If not, retrieve, save, and return.
    $cachedData = $this->cache->get($cid);
    if ($cachedData) {
      return $cachedData->data;
    }
    $request = new UserCollectionRequest(["name" => $doUsername]);
    $userData = $this->client->getEntity($request);
    if ($userData->valid()) {
      $this->cache->set($cid, $userData->current());
    }
    return $userData->current();
  }

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

sahal_va created an issue. See original summary.

sahal_va’s picture

Status: Active » Needs review

Created MR for adding a check, set cache only if the username is valid.
Please review.

hussainweb’s picture

Status: Needs review » Needs work

Thanks for the changes. This is intentional but open to debate. We don't want to keep hitting the Drupal.org servers if someone enters the wrong username and that is why we cache the failure result too. Maybe we can do it better rather than just caching an empty result?

hussainweb’s picture

Status: Needs work » Closed (works as designed)