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
Comments
Comment #3
sahal_va commentedCreated MR for adding a check, set cache only if the username is valid.
Please review.
Comment #4
hussainwebThanks 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?
Comment #5
hussainweb