|
19 | 19 |
|
20 | 20 | /** @template-extends QBMapper<View> */ |
21 | 21 | class ViewMapper extends QBMapper { |
| 22 | + use BulkFetchTrait; |
| 23 | + |
22 | 24 | protected string $table = 'tables_views'; |
23 | 25 |
|
24 | 26 | protected CappedMemoryCache $cache; |
@@ -70,17 +72,21 @@ public function findMany(array $ids): array { |
70 | 72 | return $result; |
71 | 73 | } |
72 | 74 |
|
73 | | - $qb = $this->db->getQueryBuilder(); |
74 | | - $qb->select('v.*', 't.ownership') |
75 | | - ->from($this->table, 'v') |
76 | | - ->innerJoin('v', 'tables_tables', 't', 't.id = v.table_id') |
77 | | - ->where($qb->expr()->in('v.id', $qb->createNamedParameter(array_keys($missing), IQueryBuilder::PARAM_INT_ARRAY))); |
78 | | - |
79 | | - $entities = $this->findEntities($qb); |
80 | | - foreach ($entities as $entity) { |
81 | | - $id = $entity->getId(); |
82 | | - $this->cache[(string)$id] = $entity; |
83 | | - $result[$id] = $entity; |
| 75 | + $missing = array_keys($missing); |
| 76 | + $chunkSize = $this->getMaxDbParameters(); |
| 77 | + $missingChunks = array_chunk($missing, $chunkSize); |
| 78 | + foreach ($missingChunks as $missingChunk) { |
| 79 | + $qb = $this->db->getQueryBuilder(); |
| 80 | + $qb->select('v.*', 't.ownership') |
| 81 | + ->from($this->table, 'v') |
| 82 | + ->innerJoin('v', 'tables_tables', 't', 't.id = v.table_id') |
| 83 | + ->where($qb->expr()->in('v.id', $qb->createNamedParameter($missingChunk, IQueryBuilder::PARAM_INT_ARRAY))); |
| 84 | + |
| 85 | + foreach ($this->findEntities($qb) as $entity) { |
| 86 | + $id = $entity->getId(); |
| 87 | + $this->cache[(string)$id] = $entity; |
| 88 | + $result[$id] = $entity; |
| 89 | + } |
84 | 90 | } |
85 | 91 | return $result; |
86 | 92 | } |
|
0 commit comments