|
19 | 19 | use Doctrine\ORM\EntityManagerInterface; |
20 | 20 | use Doctrine\ORM\Mapping\ClassMetadata; |
21 | 21 | use Doctrine\ORM\QueryBuilder; |
| 22 | +use Illuminate\Support\Facades\Log; |
22 | 23 | use models\summit\IOrderConstants; |
23 | 24 | use models\summit\ISummitAttendeeTicketRepository; |
24 | 25 | use models\summit\ISummitRefundRequestConstants; |
|
32 | 33 | use utils\Filter; |
33 | 34 | use utils\Order; |
34 | 35 | use utils\PagingInfo; |
| 36 | +use utils\PagingResponse; |
35 | 37 |
|
36 | 38 | /** |
37 | 39 | * Class DoctrineSummitAttendeeTicketRepository |
@@ -89,7 +91,7 @@ private function ensureJoin(QueryBuilder $qb, string $alias): void |
89 | 91 | */ |
90 | 92 | private function requiredAliases(?Filter $filter, ?Order $order): array |
91 | 93 | { |
92 | | - $need = ['a' => true]; // owner always |
| 94 | + $need = []; // owner always |
93 | 95 |
|
94 | 96 | $has = fn(string $f) => $filter?->hasFilter($f) ?? false; |
95 | 97 | $ord = fn(string $f) => $order?->hasOrder($f) ?? false; |
@@ -425,10 +427,6 @@ protected function applyExtraJoins(QueryBuilder $query, ?Filter $filter = null, |
425 | 427 | $this->ensureJoin($query, $alias); |
426 | 428 | } |
427 | 429 |
|
428 | | - // owner is always selected to prevent N+1 |
429 | | - if (\in_array('a', $query->getAllAliases(), true)) { |
430 | | - $query->addSelect('a'); // to-one fetch join is safe with pagination |
431 | | - } |
432 | 430 |
|
433 | 431 | return $query; |
434 | 432 | } |
@@ -704,4 +702,45 @@ public function getAllTicketsIdsByOrder(int $order_id, PagingInfo $paging_info): |
704 | 702 | $res = $query->getQuery()->getArrayResult(); |
705 | 703 | return array_column($res, 'id'); |
706 | 704 | } |
| 705 | + |
| 706 | + |
| 707 | + /** |
| 708 | + * @param PagingInfo $paging_info |
| 709 | + * @param Filter|null $filter |
| 710 | + * @param Order|null $order |
| 711 | + * @return PagingResponse |
| 712 | + */ |
| 713 | + public function getAllByPage(PagingInfo $paging_info, Filter $filter = null, Order $order = null){ |
| 714 | + $start = time(); |
| 715 | + Log::debug(sprintf('DoctrineSummitAttendeeTicketRepository::getAllByPage')); |
| 716 | + $total = $this->getFastCount($filter, $order); |
| 717 | + $ids = $this->getAllIdsByPage($paging_info, $filter, $order); |
| 718 | + $query = $this->getEntityManager()->createQueryBuilder() |
| 719 | + ->select('e, a, o, tt, pc, b, bt, a_c, m') |
| 720 | + ->from($this->getBaseEntity(), 'e') |
| 721 | + ->leftJoin('e.owner', 'a')->addSelect('a') |
| 722 | + ->leftJoin('e.order', 'o')->addSelect('o') |
| 723 | + ->leftJoin('e.ticket_type', 'tt')->addSelect('tt') |
| 724 | + ->leftJoin('e.promo_code', 'pc')->addSelect('pc') |
| 725 | + ->leftJoin('e.badge', 'b')->addSelect('b') |
| 726 | + ->leftJoin('b.type', 'bt')->addSelect('bt') |
| 727 | + ->leftJoin('a.company', 'a_c')->addSelect('a_c') |
| 728 | + ->leftJoin('a.member', 'm')->addSelect('m') |
| 729 | + ->where('e.id IN (:ids)') |
| 730 | + ->setParameter('ids', $ids); |
| 731 | + |
| 732 | + $data = []; |
| 733 | + foreach( $query->getQuery()->getResult() as $entity) |
| 734 | + array_push($data, $entity); |
| 735 | + $end = time() - $start; |
| 736 | + Log::debug(sprintf('DoctrineSummitAttendeeTicketRepository::getAllByPage %s seconds', $end)); |
| 737 | + return new PagingResponse |
| 738 | + ( |
| 739 | + $total, |
| 740 | + $paging_info->getPerPage(), |
| 741 | + $paging_info->getCurrentPage(), |
| 742 | + $paging_info->getLastPage($total), |
| 743 | + $data |
| 744 | + ); |
| 745 | + } |
707 | 746 | } |
0 commit comments