@@ -4746,40 +4746,31 @@ public function createOrUpdateDocumentsWithIncrease(
47464746 /**
47474747 * @var array<Change> $chunk
47484748 */
4749- \array_push (
4750- $ stack ,
4751- ...$ this ->withTransaction (fn () => Authorization::skip (fn () => $ this ->adapter ->createOrUpdateDocuments (
4752- $ collection ->getId (),
4753- $ attribute ,
4754- $ chunk
4755- )))
4756- );
4757- }
4758-
4759- $ documents = $ stack ;
4760-
4761- /**
4762- * @var array<Document> $documents
4763- */
4764- foreach ($ documents as $ key => $ document ) {
4765- /**
4766- * @var Document $document
4767- */
4768- if ($ this ->resolveRelationships ) {
4769- $ document = $ this ->silent (fn () => $ this ->populateDocumentRelationships ($ collection , $ document ));
4770- }
4749+ $ batch = $ this ->withTransaction (fn () => Authorization::skip (fn () => $ this ->adapter ->createOrUpdateDocuments (
4750+ $ collection ->getId (),
4751+ $ attribute ,
4752+ $ chunk
4753+ )));
47714754
4772- $ documents [$ key ] = $ this ->decode ($ collection , $ document );
4755+ foreach ($ batch as $ document ) {
4756+ if ($ this ->resolveRelationships ) {
4757+ $ document = $ this ->silent (fn () => $ this ->populateDocumentRelationships ($ collection , $ document ));
4758+ }
47734759
4774- if ($ this ->getSharedTables () && $ this ->getTenantPerDocument ()) {
4775- $ this ->withTenant ($ document ->getTenant (), function () use ($ collection , $ document ) {
4760+ if ($ this ->getSharedTables () && $ this ->getTenantPerDocument ()) {
4761+ $ this ->withTenant ($ document ->getTenant (), function () use ($ collection , $ document ) {
4762+ $ this ->purgeCachedDocument ($ collection ->getId (), $ document ->getId ());
4763+ });
4764+ } else {
47764765 $ this ->purgeCachedDocument ($ collection ->getId (), $ document ->getId ());
4777- });
4778- } else {
4779- $ this -> purgeCachedDocument ( $ collection -> getId (), $ document-> getId ()) ;
4766+ }
4767+
4768+ $ stack [] = $ document ;
47804769 }
47814770 }
47824771
4772+ $ documents = $ stack ;
4773+
47834774 $ this ->trigger (self ::EVENT_DOCUMENTS_UPSERT , new Document ([
47844775 '$collection ' => $ collection ->getId (),
47854776 'modified ' => \count ($ documents )
0 commit comments