Skip to content

Commit

Permalink
Repository for ClientManager and TokenManager is now instanciated on …
Browse files Browse the repository at this point in the history
…the fly, not in the constructor anymore

This avoids a database connection to be established for every request

Fixes issue FriendsOfSymfony#422
  • Loading branch information
abienvenu committed Nov 18, 2016
1 parent 1b851d7 commit 4feaf76
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
9 changes: 1 addition & 8 deletions Entity/ClientManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
use FOS\OAuthServerBundle\Model\ClientInterface;
use FOS\OAuthServerBundle\Model\ClientManager as BaseClientManager;

Expand All @@ -24,11 +23,6 @@ class ClientManager extends BaseClientManager
*/
protected $em;

/**
* @var EntityRepository
*/
protected $repository;

/**
* @var string
*/
Expand All @@ -37,7 +31,6 @@ class ClientManager extends BaseClientManager
public function __construct(ObjectManager $em, $class)
{
$this->em = $em;
$this->repository = $em->getRepository($class);
$this->class = $class;
}

Expand All @@ -54,7 +47,7 @@ public function getClass()
*/
public function findClientBy(array $criteria)
{
return $this->repository->findOneBy($criteria);
return $this->em->getRepository($this->class)->findOneBy($criteria);
}

/**
Expand Down
11 changes: 2 additions & 9 deletions Entity/TokenManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
use FOS\OAuthServerBundle\Model\TokenInterface;
use FOS\OAuthServerBundle\Model\TokenManager as BaseTokenManager;

Expand All @@ -24,11 +23,6 @@ class TokenManager extends BaseTokenManager
*/
protected $em;

/**
* @var EntityRepository
*/
protected $repository;

/**
* @var string
*/
Expand All @@ -37,7 +31,6 @@ class TokenManager extends BaseTokenManager
public function __construct(ObjectManager $em, $class)
{
$this->em = $em;
$this->repository = $em->getRepository($class);
$this->class = $class;
}

Expand All @@ -54,7 +47,7 @@ public function getClass()
*/
public function findTokenBy(array $criteria)
{
return $this->repository->findOneBy($criteria);
return $this->em->getRepository($this->class)->findOneBy($criteria);
}

/**
Expand All @@ -80,7 +73,7 @@ public function deleteToken(TokenInterface $token)
*/
public function deleteExpired()
{
$qb = $this->repository->createQueryBuilder('t');
$qb = $this->em->getRepository($this->class)->createQueryBuilder('t');
$qb
->delete()
->where('t.expiresAt < ?1')
Expand Down

0 comments on commit 4feaf76

Please sign in to comment.