mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 17:39:06 +02:00
Only fetch database user from database once.
This should improve the performance a lot.
This commit is contained in:
parent
3812cc88ff
commit
d0f2667691
1 changed files with 9 additions and 1 deletions
|
@ -33,20 +33,28 @@ use Symfony\Bridge\Doctrine\RegistryInterface;
|
|||
*/
|
||||
class UserRepository extends ServiceEntityRepository
|
||||
{
|
||||
protected $anonymous_user;
|
||||
|
||||
public function __construct(RegistryInterface $registry)
|
||||
{
|
||||
parent::__construct($registry, User::class);
|
||||
$this->anonymous_user = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the anonymous user.
|
||||
* The result is cached, so the database is only called once, after the anonymous user was found.
|
||||
*
|
||||
* @return User|null
|
||||
*/
|
||||
public function getAnonymousUser()
|
||||
{
|
||||
return $this->findOneBy([
|
||||
if ($this->anonymous_user === null) {
|
||||
$this->anonymous_user = $this->findOneBy([
|
||||
'id' => User::ID_ANONYMOUS,
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->anonymous_user;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue