forked from mirror/Part-DB.Part-DB-server
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
|
class UserRepository extends ServiceEntityRepository
|
||||||
{
|
{
|
||||||
|
protected $anonymous_user;
|
||||||
|
|
||||||
public function __construct(RegistryInterface $registry)
|
public function __construct(RegistryInterface $registry)
|
||||||
{
|
{
|
||||||
parent::__construct($registry, User::class);
|
parent::__construct($registry, User::class);
|
||||||
|
$this->anonymous_user = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the anonymous user.
|
* Returns the anonymous user.
|
||||||
|
* The result is cached, so the database is only called once, after the anonymous user was found.
|
||||||
*
|
*
|
||||||
* @return User|null
|
* @return User|null
|
||||||
*/
|
*/
|
||||||
public function getAnonymousUser()
|
public function getAnonymousUser()
|
||||||
{
|
{
|
||||||
return $this->findOneBy([
|
if ($this->anonymous_user === null) {
|
||||||
|
$this->anonymous_user = $this->findOneBy([
|
||||||
'id' => User::ID_ANONYMOUS,
|
'id' => User::ID_ANONYMOUS,
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->anonymous_user;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue