File tree Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Original file line number Diff line number Diff line change 1212 * limitations under the License.
1313 **/
1414
15+ use Doctrine \ORM \Query ;
1516use Doctrine \ORM \QueryBuilder ;
1617use Models \OAuth2 \Client ;
1718use 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 /**
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments