diff --git a/app/config/collections.php b/app/config/collections.php index 5648bfe6ea..12904a1e20 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -3410,6 +3410,17 @@ $collections = [ 'default' => null, 'filters' => [], ], + [ + 'array' => false, + '$id' => ID::custom('bucketInternalId'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => true, + 'default' => null, + 'filters' => [], + ], [ '$id' => ID::custom('name'), 'type' => Database::VAR_STRING, diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index bee37d0b1e..ab5febf8fa 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -561,6 +561,7 @@ App::post('/v1/storage/buckets/:bucketId/files') '$id' => $fileId, '$permissions' => $permissions, 'bucketId' => $bucket->getId(), + 'bucketInternalId' => $bucket->getInternalId(), 'name' => $fileName, 'path' => $path, 'signature' => $fileHash, @@ -610,6 +611,7 @@ App::post('/v1/storage/buckets/:bucketId/files') '$id' => ID::custom($fileId), '$permissions' => $permissions, 'bucketId' => $bucket->getId(), + 'bucketInternalId' => $bucket->getInternalId(), 'name' => $fileName, 'path' => $path, 'signature' => '', diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index f7d80b21a7..9fe0574df5 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -112,13 +112,11 @@ $databaseListener = function (string $event, Document $document, Document $proje } break; case str_starts_with($document->getCollection(), 'bucket_'): // files - $parts = explode('_', $document->getCollection()); - $bucketInternalId = $parts[1]; $queueForUsage ->addMetric(METRIC_FILES, $value) // per project ->addMetric(METRIC_FILES_STORAGE, $document->getAttribute('sizeOriginal') * $value) // per project - ->addMetric(str_replace('{bucketInternalId}', $bucketInternalId, METRIC_BUCKET_ID_FILES), $value) // per bucket - ->addMetric(str_replace('{bucketInternalId}', $bucketInternalId, METRIC_BUCKET_ID_FILES_STORAGE), $document->getAttribute('sizeOriginal') * $value); // per bucket + ->addMetric(str_replace('{bucketInternalId}', $document->getAttribute('bucketInternalId'), METRIC_BUCKET_ID_FILES), $value) // per bucket + ->addMetric(str_replace('{bucketInternalId}', $document->getAttribute('bucketInternalId'), METRIC_BUCKET_ID_FILES_STORAGE), $document->getAttribute('sizeOriginal') * $value); // per bucket break; case $document->getCollection() === 'functions': $queueForUsage diff --git a/app/workers/usage.php b/app/workers/usage.php index b0778f4cd4..135e64872d 100644 --- a/app/workers/usage.php +++ b/app/workers/usage.php @@ -28,8 +28,8 @@ $periods['inf'] = '0000-00-00 00:00'; const INFINITI_PERIOD = '_inf_'; /** - * On Documents that tied by relations like functions>deployments>build || documents>collection>database || buckets>files - * When we remove a parent document we need to deduct his children aggregation from the project scope + * On Documents that tied by relations like functions>deployments>build || documents>collection>database || buckets>files. + * When we remove a parent document we need to deduct his children aggregation from the project scope. */ Server::setResource('reduce', function (Cache $cache, Registry $register, $pools) { return function ($database, $projectInternalId, Document $document, array &$metrics) use ($pools, $cache, $register): void {