Skip to content

Commit c7bc055

Browse files
committed
Purge external database cache on createAttribute
1 parent efb8087 commit c7bc055

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

app/controllers/api/database.php

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@
4040
* @param Utopia\Database\Document $attribute
4141
* @param Appwrite\Utopia\Response $response
4242
* @param Utopia\Database\Database $dbForInternal
43+
* @param Utopia\Database\Database $dbForExternal
4344
* @param Appwrite\Event\Event $database
4445
* @param Appwrite\Event\Event $audits
4546
* @param Appwrite\Stats\Stats $usage
4647
*
4748
* @return Document Newly created attribute document
4849
*/
49-
function createAttribute($collectionId, $attribute, $response, $dbForInternal, $database, $audits, $usage): Document
50+
function createAttribute($collectionId, $attribute, $response, $dbForInternal, $dbForExternal, $database, $audits, $usage): Document
5051
{
5152
$attributeId = $attribute->getId();
5253
$type = $attribute->getAttribute('type', '');
@@ -107,6 +108,7 @@ function createAttribute($collectionId, $attribute, $response, $dbForInternal, $
107108
}
108109

109110
$dbForInternal->deleteCachedDocument('collections', $collectionId);
111+
$dbForExternal->deleteCachedCollection($collectionId);
110112

111113
// Pass clone of $attribute object to workers
112114
// so we can later modify Document to fit response model
@@ -688,12 +690,14 @@ function createAttribute($collectionId, $attribute, $response, $dbForInternal, $
688690
->param('array', false, new Boolean(), 'Is attribute an array?', true)
689691
->inject('response')
690692
->inject('dbForInternal')
693+
->inject('dbForExternal')
691694
->inject('database')
692695
->inject('audits')
693696
->inject('usage')
694-
->action(function ($collectionId, $attributeId, $size, $required, $default, $array, $response, $dbForInternal, $database, $audits, $usage) {
697+
->action(function ($collectionId, $attributeId, $size, $required, $default, $array, $response, $dbForInternal, $dbForExternal, $database, $audits, $usage) {
695698
/** @var Appwrite\Utopia\Response $response */
696699
/** @var Utopia\Database\Database $dbForInternal*/
700+
/** @var Utopia\Database\Database $dbForExternal*/
697701
/** @var Appwrite\Event\Event $database */
698702
/** @var Appwrite\Event\Event $audits */
699703
/** @var Appwrite\Stats\Stats $usage */
@@ -711,7 +715,7 @@ function createAttribute($collectionId, $attribute, $response, $dbForInternal, $
711715
'required' => $required,
712716
'default' => $default,
713717
'array' => $array,
714-
]), $response, $dbForInternal, $database, $audits, $usage);
718+
]), $response, $dbForInternal, $dbForExternal, $database, $audits, $usage);
715719

716720
$response->dynamic($attribute, Response::MODEL_ATTRIBUTE_STRING);
717721
});
@@ -735,12 +739,14 @@ function createAttribute($collectionId, $attribute, $response, $dbForInternal, $
735739
->param('array', false, new Boolean(), 'Is attribute an array?', true)
736740
->inject('response')
737741
->inject('dbForInternal')
742+
->inject('dbForExternal')
738743
->inject('database')
739744
->inject('audits')
740745
->inject('usage')
741-
->action(function ($collectionId, $attributeId, $required, $default, $array, $response, $dbForInternal, $database, $audits, $usage) {
746+
->action(function ($collectionId, $attributeId, $required, $default, $array, $response, $dbForInternal, $dbForExternal, $database, $audits, $usage) {
742747
/** @var Appwrite\Utopia\Response $response */
743748
/** @var Utopia\Database\Database $dbForInternal*/
749+
/** @var Utopia\Database\Database $dbForExternal*/
744750
/** @var Appwrite\Event\Event $database */
745751
/** @var Appwrite\Event\Event $audits */
746752
/** @var Appwrite\Stats\Stats $usage */
@@ -753,7 +759,7 @@ function createAttribute($collectionId, $attribute, $response, $dbForInternal, $
753759
'default' => $default,
754760
'array' => $array,
755761
'format' => APP_DATABASE_ATTRIBUTE_EMAIL,
756-
]), $response, $dbForInternal, $database, $audits, $usage);
762+
]), $response, $dbForInternal, $dbForExternal, $database, $audits, $usage);
757763

758764
$response->dynamic($attribute, Response::MODEL_ATTRIBUTE_EMAIL);
759765
});
@@ -778,12 +784,14 @@ function createAttribute($collectionId, $attribute, $response, $dbForInternal, $
778784
->param('array', false, new Boolean(), 'Is attribute an array?', true)
779785
->inject('response')
780786
->inject('dbForInternal')
787+
->inject('dbForExternal')
781788
->inject('database')
782789
->inject('audits')
783790
->inject('usage')
784-
->action(function ($collectionId, $attributeId, $elements, $required, $default, $array, $response, $dbForInternal, $database, $audits, $usage) {
791+
->action(function ($collectionId, $attributeId, $elements, $required, $default, $array, $response, $dbForInternal, $dbForExternal, $database, $audits, $usage) {
785792
/** @var Appwrite\Utopia\Response $response */
786793
/** @var Utopia\Database\Database $dbForInternal*/
794+
/** @var Utopia\Database\Database $dbForExternal*/
787795
/** @var Appwrite\Event\Event $database */
788796
/** @var Appwrite\Event\Event $audits */
789797
/** @var Appwrite\Stats\Stats $usage */
@@ -808,7 +816,7 @@ function createAttribute($collectionId, $attribute, $response, $dbForInternal, $
808816
'array' => $array,
809817
'format' => APP_DATABASE_ATTRIBUTE_ENUM,
810818
'formatOptions' => ['elements' => $elements],
811-
]), $response, $dbForInternal, $database, $audits, $usage);
819+
]), $response, $dbForInternal, $dbForExternal, $database, $audits, $usage);
812820

813821
$response->dynamic($attribute, Response::MODEL_ATTRIBUTE_ENUM);
814822
});
@@ -832,12 +840,14 @@ function createAttribute($collectionId, $attribute, $response, $dbForInternal, $
832840
->param('array', false, new Boolean(), 'Is attribute an array?', true)
833841
->inject('response')
834842
->inject('dbForInternal')
843+
->inject('dbForExternal')
835844
->inject('database')
836845
->inject('audits')
837846
->inject('usage')
838-
->action(function ($collectionId, $attributeId, $required, $default, $array, $response, $dbForInternal, $database, $audits, $usage) {
847+
->action(function ($collectionId, $attributeId, $required, $default, $array, $response, $dbForInternal, $dbForExternal, $database, $audits, $usage) {
839848
/** @var Appwrite\Utopia\Response $response */
840849
/** @var Utopia\Database\Database $dbForInternal*/
850+
/** @var Utopia\Database\Database $dbForExternal*/
841851
/** @var Appwrite\Event\Event $database */
842852
/** @var Appwrite\Event\Event $audits */
843853
/** @var Appwrite\Stats\Stats $usage */
@@ -850,7 +860,7 @@ function createAttribute($collectionId, $attribute, $response, $dbForInternal, $
850860
'default' => $default,
851861
'array' => $array,
852862
'format' => APP_DATABASE_ATTRIBUTE_IP,
853-
]), $response, $dbForInternal, $database, $audits, $usage);
863+
]), $response, $dbForInternal, $dbForExternal, $database, $audits, $usage);
854864

855865
$response->dynamic($attribute, Response::MODEL_ATTRIBUTE_IP);
856866
});
@@ -874,10 +884,11 @@ function createAttribute($collectionId, $attribute, $response, $dbForInternal, $
874884
->param('array', false, new Boolean(), 'Is attribute an array?', true)
875885
->inject('response')
876886
->inject('dbForInternal')
887+
->inject('dbForExternal')
877888
->inject('database')
878889
->inject('audits')
879890
->inject('usage')
880-
->action(function ($collectionId, $attributeId, $required, $default, $array, $response, $dbForInternal, $database, $audits, $usage) {
891+
->action(function ($collectionId, $attributeId, $required, $default, $array, $response, $dbForInternal, $dbForExternal, $database, $audits, $usage) {
881892
/** @var Appwrite\Utopia\Response $response */
882893
/** @var Utopia\Database\Database $dbForExternal*/
883894
/** @var Appwrite\Event\Event $database */
@@ -892,7 +903,7 @@ function createAttribute($collectionId, $attribute, $response, $dbForInternal, $
892903
'default' => $default,
893904
'array' => $array,
894905
'format' => APP_DATABASE_ATTRIBUTE_URL,
895-
]), $response, $dbForInternal, $database, $audits, $usage);
906+
]), $response, $dbForInternal, $dbForExternal, $database, $audits, $usage);
896907

897908
$response->dynamic($attribute, Response::MODEL_ATTRIBUTE_URL);
898909
});
@@ -918,12 +929,14 @@ function createAttribute($collectionId, $attribute, $response, $dbForInternal, $
918929
->param('array', false, new Boolean(), 'Is attribute an array?', true)
919930
->inject('response')
920931
->inject('dbForInternal')
932+
->inject('dbForExternal')
921933
->inject('database')
922934
->inject('audits')
923935
->inject('usage')
924-
->action(function ($collectionId, $attributeId, $required, $min, $max, $default, $array, $response, $dbForInternal, $database, $audits, $usage) {
936+
->action(function ($collectionId, $attributeId, $required, $min, $max, $default, $array, $response, $dbForInternal, $dbForExternal, $database, $audits, $usage) {
925937
/** @var Appwrite\Utopia\Response $response */
926938
/** @var Utopia\Database\Database $dbForInternal*/
939+
/** @var Utopia\Database\Database $dbForExternal*/
927940
/** @var Appwrite\Event\Event $database */
928941
/** @var Appwrite\Event\Event $audits */
929942
/** @var Appwrite\Stats\Stats $usage */
@@ -954,7 +967,7 @@ function createAttribute($collectionId, $attribute, $response, $dbForInternal, $
954967
'min' => $min,
955968
'max' => $max,
956969
],
957-
]), $response, $dbForInternal, $database, $audits, $usage);
970+
]), $response, $dbForInternal, $dbForExternal, $database, $audits, $usage);
958971

959972
$formatOptions = $attribute->getAttribute('formatOptions', []);
960973

@@ -987,12 +1000,14 @@ function createAttribute($collectionId, $attribute, $response, $dbForInternal, $
9871000
->param('array', false, new Boolean(), 'Is attribute an array?', true)
9881001
->inject('response')
9891002
->inject('dbForInternal')
1003+
->inject('dbForExternal')
9901004
->inject('database')
9911005
->inject('audits')
9921006
->inject('usage')
993-
->action(function ($collectionId, $attributeId, $required, $min, $max, $default, $array, $response, $dbForInternal, $database, $audits, $usage) {
1007+
->action(function ($collectionId, $attributeId, $required, $min, $max, $default, $array, $response, $dbForInternal, $dbForExternal,$database, $audits, $usage) {
9941008
/** @var Appwrite\Utopia\Response $response */
9951009
/** @var Utopia\Database\Database $dbForInternal*/
1010+
/** @var Utopia\Database\Database $dbForExternal*/
9961011
/** @var Appwrite\Event\Event $database */
9971012
/** @var Appwrite\Event\Event $audits */
9981013
/** @var Appwrite\Stats\Stats $usage */
@@ -1023,7 +1038,7 @@ function createAttribute($collectionId, $attribute, $response, $dbForInternal, $
10231038
'min' => $min,
10241039
'max' => $max,
10251040
],
1026-
]), $response, $dbForInternal, $database, $audits, $usage);
1041+
]), $response, $dbForInternal, $dbForExternal, $database, $audits, $usage);
10271042

10281043
$formatOptions = $attribute->getAttribute('formatOptions', []);
10291044

@@ -1054,10 +1069,11 @@ function createAttribute($collectionId, $attribute, $response, $dbForInternal, $
10541069
->param('array', false, new Boolean(), 'Is attribute an array?', true)
10551070
->inject('response')
10561071
->inject('dbForInternal')
1072+
->inject('dbForExternal')
10571073
->inject('database')
10581074
->inject('audits')
10591075
->inject('usage')
1060-
->action(function ($collectionId, $attributeId, $required, $default, $array, $response, $dbForInternal, $database, $audits, $usage) {
1076+
->action(function ($collectionId, $attributeId, $required, $default, $array, $response, $dbForInternal, $dbForExternal, $database, $audits, $usage) {
10611077
/** @var Appwrite\Utopia\Response $response */
10621078
/** @var Utopia\Database\Database $dbForInternal*/
10631079
/** @var Appwrite\Event\Event $database */
@@ -1071,7 +1087,7 @@ function createAttribute($collectionId, $attribute, $response, $dbForInternal, $
10711087
'required' => $required,
10721088
'default' => $default,
10731089
'array' => $array,
1074-
]), $response, $dbForInternal, $database, $audits, $usage);
1090+
]), $response, $dbForInternal, $dbForExternal, $database, $audits, $usage);
10751091

10761092
$response->dynamic($attribute, Response::MODEL_ATTRIBUTE_BOOLEAN);
10771093
});

0 commit comments

Comments
 (0)