Skip to content

Commit faf44fc

Browse files
committed
fix: improve instropection perfomance
prefetch client resource server
1 parent 0484778 commit faf44fc

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

app/Repositories/DoctrineOAuth2ClientRepository.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* limitations under the License.
1313
**/
1414

15+
use Doctrine\ORM\Query;
1516
use Doctrine\ORM\QueryBuilder;
1617
use Models\OAuth2\Client;
1718
use OAuth2\Repositories\IClientRepository;
@@ -103,18 +104,29 @@ public function getClientById(string $client_id):?Client
103104
* @return Client|null
104105
* @throws \Doctrine\ORM\NonUniqueResultException
105106
*/
106-
public function getClientByIdCacheable(string $client_id):?Client
107+
public function getClientByIdCacheable(string $client_id, bool $withResourceServer = true):?Client
107108
{
108109
return $this->getEntityManager()
109110
->createQueryBuilder()
110111
->select("c")
111112
->from($this->getBaseEntity(), "c")
112113
->where("c.client_id = (:client_id)")
113114
->setParameter("client_id", trim($client_id))
114-
->setMaxResults(1)
115-
->getQuery()
116-
->setCacheable(true)
117-
->getOneOrNullResult();
115+
->setMaxResults(1);
116+
117+
if ($withResourceServer) {
118+
// fetch join dirigido
119+
$qb->addSelect('rs')
120+
->leftJoin('c.resource_server', 'rs'); // JOIN FETCH implícito por el addSelect + asociación
121+
}
122+
123+
$q = $qb->getQuery();
124+
125+
$q->useQueryCache(true);
126+
$q->enableResultCache(600, 'client_by_id_'.$client_id); // TTL 10 min
127+
$q->setHint(Query::HINT_READ_ONLY, true);
128+
129+
return $q->getOneOrNullResult();
118130
}
119131

120132
/**

app/libs/OAuth2/Repositories/IClientRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public function getClientById(string $client_id):?Client;
3333

3434
/**
3535
* @param string $client_id
36+
* @param bool $withResourceServer
3637
* @return Client|null
37-
* @throws \Doctrine\ORM\NonUniqueResultException
3838
*/
39-
public function getClientByIdCacheable(string $client_id):?Client;
39+
public function getClientByIdCacheable(string $client_id, bool $withResourceServer = true):?Client;
4040

4141
/**
4242
* @param int $id

0 commit comments

Comments
 (0)