@@ -1595,6 +1595,7 @@ public function createAttribute(string $collection, string $id, string $type, in
15951595 );
15961596
15971597 $ created = false ;
1598+ $ metadataModified = false ;
15981599 try {
15991600 $ created = $ this ->adapter ->createAttribute ($ collection ->getId (), $ id , $ type , $ size , $ signed , $ array );
16001601
@@ -1604,6 +1605,7 @@ public function createAttribute(string $collection, string $id, string $type, in
16041605
16051606 if ($ collection ->getId () !== self ::METADATA ) {
16061607 $ this ->silent (fn () => $ this ->updateDocument (self ::METADATA , $ collection ->getId (), $ collection ));
1608+ $ metadataModified = true ;
16071609 }
16081610
16091611 $ this ->trigger (self ::EVENT_ATTRIBUTE_CREATE , $ attribute );
@@ -1617,14 +1619,15 @@ public function createAttribute(string $collection, string $id, string $type, in
16171619
16181620 if ($ collection ->getId () !== self ::METADATA ) {
16191621 $ this ->silent (fn () => $ this ->updateDocument (self ::METADATA , $ collection ->getId (), $ collection ));
1622+ $ metadataModified = true ;
16201623 }
16211624
16221625 $ this ->trigger (self ::EVENT_ATTRIBUTE_CREATE , $ attribute );
16231626
16241627 return true ;
16251628 } finally {
1626- // Ensure collection cache is cleared even if trigger fails after adapter changes
1627- if ($ created ) {
1629+ // Ensure collection cache is cleared if either adapter succeeded OR metadata was modified
1630+ if ($ created || $ metadataModified ) {
16281631 $ this ->purgeCachedCollection ($ collection ->getId ());
16291632 }
16301633 }
@@ -1713,6 +1716,7 @@ public function createAttributes(string $collection, array $attributes): bool
17131716 }
17141717
17151718 $ created = false ;
1719+ $ metadataModified = false ;
17161720 try {
17171721 $ created = $ this ->adapter ->createAttributes ($ collection ->getId (), $ attributes );
17181722
@@ -1722,6 +1726,7 @@ public function createAttributes(string $collection, array $attributes): bool
17221726
17231727 if ($ collection ->getId () !== self ::METADATA ) {
17241728 $ this ->silent (fn () => $ this ->updateDocument (self ::METADATA , $ collection ->getId (), $ collection ));
1729+ $ metadataModified = true ;
17251730 }
17261731
17271732 $ this ->trigger (self ::EVENT_ATTRIBUTE_CREATE , $ attributeDocuments );
@@ -1736,14 +1741,15 @@ public function createAttributes(string $collection, array $attributes): bool
17361741
17371742 if ($ collection ->getId () !== self ::METADATA ) {
17381743 $ this ->silent (fn () => $ this ->updateDocument (self ::METADATA , $ collection ->getId (), $ collection ));
1744+ $ metadataModified = true ;
17391745 }
17401746
17411747 $ this ->trigger (self ::EVENT_ATTRIBUTE_CREATE , $ attributeDocuments );
17421748
17431749 return true ;
17441750 } finally {
1745- // Ensure cache is cleared even if trigger fails after adapter changes
1746- if ($ created ) {
1751+ // Ensure cache is cleared if either adapter succeeded OR metadata was modified
1752+ if ($ created || $ metadataModified ) {
17471753 $ this ->purgeCachedCollection ($ collection ->getId ());
17481754 $ this ->purgeCachedDocument (self ::METADATA , $ collection ->getId ());
17491755 }
@@ -3180,6 +3186,7 @@ public function createIndex(string $collection, string $id, string $type, array
31803186 }
31813187
31823188 $ created = false ;
3189+ $ metadataModified = false ;
31833190 try {
31843191 $ created = $ this ->adapter ->createIndex ($ collection ->getId (), $ id , $ type , $ attributes , $ lengths , $ orders , $ indexAttributesWithTypes );
31853192
@@ -3189,6 +3196,7 @@ public function createIndex(string $collection, string $id, string $type, array
31893196
31903197 if ($ collection ->getId () !== self ::METADATA ) {
31913198 $ this ->silent (fn () => $ this ->updateDocument (self ::METADATA , $ collection ->getId (), $ collection ));
3199+ $ metadataModified = true ;
31923200 }
31933201
31943202 $ this ->trigger (self ::EVENT_INDEX_CREATE , $ index );
@@ -3202,14 +3210,15 @@ public function createIndex(string $collection, string $id, string $type, array
32023210
32033211 if ($ collection ->getId () !== self ::METADATA ) {
32043212 $ this ->silent (fn () => $ this ->updateDocument (self ::METADATA , $ collection ->getId (), $ collection ));
3213+ $ metadataModified = true ;
32053214 }
32063215
32073216 $ this ->trigger (self ::EVENT_INDEX_CREATE , $ index );
32083217
32093218 return true ;
32103219 } finally {
3211- // Ensure collection cache is cleared even if trigger fails after adapter changes
3212- if ($ created ) {
3220+ // Ensure collection cache is cleared if either adapter succeeded OR metadata was modified
3221+ if ($ created || $ metadataModified ) {
32133222 $ this ->purgeCachedCollection ($ collection ->getId ());
32143223 }
32153224 }
0 commit comments