mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
perf: prevent N+1 on watchlist fetch
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Entity\Watchlist;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
@@ -33,6 +34,24 @@ class WatchlistRepository extends ServiceEntityRepository
|
||||
->getQuery()->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Watchlist[]
|
||||
*/
|
||||
public function fetchWatchlistsForUser(User $user): array
|
||||
{
|
||||
return $this->createQueryBuilder('w')
|
||||
->addSelect('d')
|
||||
->addSelect('e')
|
||||
->addSelect('p')
|
||||
->leftJoin('w.domains', 'd')
|
||||
->leftJoin('d.events', 'e')
|
||||
->leftJoin('d.domainPurchases', 'p')
|
||||
->where('w.user = :user')
|
||||
->setParameter('user', $user)
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return Watchlist[] Returns an array of Watchlist objects
|
||||
// */
|
||||
|
||||
Reference in New Issue
Block a user