Skip cache set if given username is invalid

Created on 21 November 2022, over 1 year ago
Updated 18 October 2023, 8 months ago

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

📌 Task
Status

Closed: works as designed

Version

1.0

Component

Code

Created by

🇮🇳India sahal_va

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.

Production build 0.69.0 2024