1
0
Fork 0
mirror of https://codeberg.org/demostf/api.git synced 2026-06-03 18:04:08 +02:00

use the most common name for users on profile listing

This commit is contained in:
Robin Appelman 2019-05-03 00:24:16 +02:00
commit fba3778787
2 changed files with 15 additions and 2 deletions

View file

@ -5,7 +5,7 @@ php:
- '7.3'
addons:
postgresql: "9.6"
postgresql: "11"
cache:
directories:

View file

@ -47,13 +47,26 @@ class UserProvider extends BaseProvider {
}
public function get(string $steamid): ?User {
// first search in the view which contains the most used name for the users
$query = $this->getQueryBuilder();
$query->select(['id', 'steamid', 'name', 'avatar', 'token'])
->from('users')
->from('users_named')
->where($query->expr()->eq('steamid', $query->createNamedParameter($steamid)));
$row = $query->execute()->fetch();
if (!$row) {
// if the user is newly inserted it wont be in our view yet
$query = $this->getQueryBuilder();
$query->select(['id', 'steamid', 'name', 'avatar', 'token'])
->from('users')
->where($query->expr()->eq('steamid', $query->createNamedParameter($steamid)));
$row = $query->execute()->fetch();
}
return $row ? User::fromRow($row) : null;
}