Merge pull request #5515 from appwrite/file_internal_id
bucketInternalId attribute to files collection
This commit is contained in:
commit
4dd1f5710b
4 changed files with 30 additions and 19 deletions
|
@ -3410,6 +3410,17 @@ $collections = [
|
||||||
'default' => null,
|
'default' => null,
|
||||||
'filters' => [],
|
'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'),
|
'$id' => ID::custom('name'),
|
||||||
'type' => Database::VAR_STRING,
|
'type' => Database::VAR_STRING,
|
||||||
|
|
|
@ -561,6 +561,7 @@ App::post('/v1/storage/buckets/:bucketId/files')
|
||||||
'$id' => $fileId,
|
'$id' => $fileId,
|
||||||
'$permissions' => $permissions,
|
'$permissions' => $permissions,
|
||||||
'bucketId' => $bucket->getId(),
|
'bucketId' => $bucket->getId(),
|
||||||
|
'bucketInternalId' => $bucket->getInternalId(),
|
||||||
'name' => $fileName,
|
'name' => $fileName,
|
||||||
'path' => $path,
|
'path' => $path,
|
||||||
'signature' => $fileHash,
|
'signature' => $fileHash,
|
||||||
|
@ -610,6 +611,7 @@ App::post('/v1/storage/buckets/:bucketId/files')
|
||||||
'$id' => ID::custom($fileId),
|
'$id' => ID::custom($fileId),
|
||||||
'$permissions' => $permissions,
|
'$permissions' => $permissions,
|
||||||
'bucketId' => $bucket->getId(),
|
'bucketId' => $bucket->getId(),
|
||||||
|
'bucketInternalId' => $bucket->getInternalId(),
|
||||||
'name' => $fileName,
|
'name' => $fileName,
|
||||||
'path' => $path,
|
'path' => $path,
|
||||||
'signature' => '',
|
'signature' => '',
|
||||||
|
|
|
@ -112,13 +112,11 @@ $databaseListener = function (string $event, Document $document, Document $proje
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case str_starts_with($document->getCollection(), 'bucket_'): // files
|
case str_starts_with($document->getCollection(), 'bucket_'): // files
|
||||||
$parts = explode('_', $document->getCollection());
|
|
||||||
$bucketInternalId = $parts[1];
|
|
||||||
$queueForUsage
|
$queueForUsage
|
||||||
->addMetric(METRIC_FILES, $value) // per project
|
->addMetric(METRIC_FILES, $value) // per project
|
||||||
->addMetric(METRIC_FILES_STORAGE, $document->getAttribute('sizeOriginal') * $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}', $document->getAttribute('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_STORAGE), $document->getAttribute('sizeOriginal') * $value); // per bucket
|
||||||
break;
|
break;
|
||||||
case $document->getCollection() === 'functions':
|
case $document->getCollection() === 'functions':
|
||||||
$queueForUsage
|
$queueForUsage
|
||||||
|
|
|
@ -25,11 +25,11 @@ $periods['1d'] = 'Y-m-d 00:00';
|
||||||
//$periods['1m'] = 'Y-m-1 00:00';
|
//$periods['1m'] = 'Y-m-1 00:00';
|
||||||
$periods['inf'] = '0000-00-00 00:00';
|
$periods['inf'] = '0000-00-00 00:00';
|
||||||
|
|
||||||
const INFINITI_PERIOD = '_inf_';
|
const INFINITY_PERIOD = '_inf_';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* On Documents that tied by relations like functions>deployments>build || documents>collection>database || buckets>files
|
* 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
|
* 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) {
|
Server::setResource('reduce', function (Cache $cache, Registry $register, $pools) {
|
||||||
return function ($database, $projectInternalId, Document $document, array &$metrics) use ($pools, $cache, $register): void {
|
return function ($database, $projectInternalId, Document $document, array &$metrics) use ($pools, $cache, $register): void {
|
||||||
|
@ -55,8 +55,8 @@ Server::setResource('reduce', function (Cache $cache, Registry $register, $pools
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case $document->getCollection() === 'databases': // databases
|
case $document->getCollection() === 'databases': // databases
|
||||||
$collections = $dbForProject->getDocument('stats', md5(INFINITI_PERIOD . str_replace('{databaseInternalId}', $document->getInternalId(), METRIC_DATABASE_ID_COLLECTIONS)));
|
$collections = $dbForProject->getDocument('stats', md5(INFINITY_PERIOD . str_replace('{databaseInternalId}', $document->getInternalId(), METRIC_DATABASE_ID_COLLECTIONS)));
|
||||||
$documents = $dbForProject->getDocument('stats', md5(INFINITI_PERIOD . str_replace('{databaseInternalId}', $document->getInternalId(), METRIC_DATABASE_ID_DOCUMENTS)));
|
$documents = $dbForProject->getDocument('stats', md5(INFINITY_PERIOD . str_replace('{databaseInternalId}', $document->getInternalId(), METRIC_DATABASE_ID_DOCUMENTS)));
|
||||||
if (!empty($collections['value'])) {
|
if (!empty($collections['value'])) {
|
||||||
$metrics[] = [
|
$metrics[] = [
|
||||||
'key' => METRIC_COLLECTIONS,
|
'key' => METRIC_COLLECTIONS,
|
||||||
|
@ -74,7 +74,7 @@ Server::setResource('reduce', function (Cache $cache, Registry $register, $pools
|
||||||
case str_starts_with($document->getCollection(), 'database_') && !str_contains($document->getCollection(), 'collection'): //collections
|
case str_starts_with($document->getCollection(), 'database_') && !str_contains($document->getCollection(), 'collection'): //collections
|
||||||
$parts = explode('_', $document->getCollection());
|
$parts = explode('_', $document->getCollection());
|
||||||
$databaseInternalId = $parts[1] ?? 0;
|
$databaseInternalId = $parts[1] ?? 0;
|
||||||
$documents = $dbForProject->getDocument('stats', md5(INFINITI_PERIOD . str_replace(['{databaseInternalId}', '{collectionInternalId}'], [$databaseInternalId, $document->getInternalId()], METRIC_DATABASE_ID_COLLECTION_ID_DOCUMENTS)));
|
$documents = $dbForProject->getDocument('stats', md5(INFINITY_PERIOD . str_replace(['{databaseInternalId}', '{collectionInternalId}'], [$databaseInternalId, $document->getInternalId()], METRIC_DATABASE_ID_COLLECTION_ID_DOCUMENTS)));
|
||||||
|
|
||||||
if (!empty($documents['value'])) {
|
if (!empty($documents['value'])) {
|
||||||
$metrics[] = [
|
$metrics[] = [
|
||||||
|
@ -89,8 +89,8 @@ Server::setResource('reduce', function (Cache $cache, Registry $register, $pools
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case $document->getCollection() === 'buckets':
|
case $document->getCollection() === 'buckets':
|
||||||
$files = $dbForProject->getDocument('stats', md5(INFINITI_PERIOD . str_replace('{bucketInternalId}', $document->getInternalId(), METRIC_BUCKET_ID_FILES)));
|
$files = $dbForProject->getDocument('stats', md5(INFINITY_PERIOD . str_replace('{bucketInternalId}', $document->getInternalId(), METRIC_BUCKET_ID_FILES)));
|
||||||
$storage = $dbForProject->getDocument('stats', md5(INFINITI_PERIOD . str_replace('{bucketInternalId}', $document->getInternalId(), METRIC_BUCKET_ID_FILES_STORAGE)));
|
$storage = $dbForProject->getDocument('stats', md5(INFINITY_PERIOD . str_replace('{bucketInternalId}', $document->getInternalId(), METRIC_BUCKET_ID_FILES_STORAGE)));
|
||||||
|
|
||||||
if (!empty($files['value'])) {
|
if (!empty($files['value'])) {
|
||||||
$metrics[] = [
|
$metrics[] = [
|
||||||
|
@ -108,13 +108,13 @@ Server::setResource('reduce', function (Cache $cache, Registry $register, $pools
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case $document->getCollection() === 'functions':
|
case $document->getCollection() === 'functions':
|
||||||
$deployments = $dbForProject->getDocument('stats', md5(INFINITI_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], ['functions', $document->getInternalId()], METRIC_FUNCTION_ID_DEPLOYMENTS)));
|
$deployments = $dbForProject->getDocument('stats', md5(INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], ['functions', $document->getInternalId()], METRIC_FUNCTION_ID_DEPLOYMENTS)));
|
||||||
$deploymentsStorage = $dbForProject->getDocument('stats', md5(INFINITI_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], ['functions', $document->getInternalId()], METRIC_FUNCTION_ID_DEPLOYMENTS_STORAGE)));
|
$deploymentsStorage = $dbForProject->getDocument('stats', md5(INFINITY_PERIOD . str_replace(['{resourceType}', '{resourceInternalId}'], ['functions', $document->getInternalId()], METRIC_FUNCTION_ID_DEPLOYMENTS_STORAGE)));
|
||||||
$builds = $dbForProject->getDocument('stats', md5(INFINITI_PERIOD . str_replace('{functionInternalId}', $document->getInternalId(), METRIC_FUNCTION_ID_BUILDS)));
|
$builds = $dbForProject->getDocument('stats', md5(INFINITY_PERIOD . str_replace('{functionInternalId}', $document->getInternalId(), METRIC_FUNCTION_ID_BUILDS)));
|
||||||
$buildsStorage = $dbForProject->getDocument('stats', md5(INFINITI_PERIOD . str_replace('{functionInternalId}', $document->getInternalId(), METRIC_FUNCTION_ID_BUILDS_STORAGE)));
|
$buildsStorage = $dbForProject->getDocument('stats', md5(INFINITY_PERIOD . str_replace('{functionInternalId}', $document->getInternalId(), METRIC_FUNCTION_ID_BUILDS_STORAGE)));
|
||||||
$buildsCompute = $dbForProject->getDocument('stats', md5(INFINITI_PERIOD . str_replace('{functionInternalId}', $document->getInternalId(), METRIC_FUNCTION_ID_BUILDS_COMPUTE)));
|
$buildsCompute = $dbForProject->getDocument('stats', md5(INFINITY_PERIOD . str_replace('{functionInternalId}', $document->getInternalId(), METRIC_FUNCTION_ID_BUILDS_COMPUTE)));
|
||||||
$executions = $dbForProject->getDocument('stats', md5(INFINITI_PERIOD . str_replace('{functionInternalId}', $document->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS)));
|
$executions = $dbForProject->getDocument('stats', md5(INFINITY_PERIOD . str_replace('{functionInternalId}', $document->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS)));
|
||||||
$executionsCompute = $dbForProject->getDocument('stats', md5(INFINITI_PERIOD . str_replace('{functionInternalId}', $document->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS_COMPUTE)));
|
$executionsCompute = $dbForProject->getDocument('stats', md5(INFINITY_PERIOD . str_replace('{functionInternalId}', $document->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS_COMPUTE)));
|
||||||
|
|
||||||
if (!empty($deployments['value'])) {
|
if (!empty($deployments['value'])) {
|
||||||
$metrics[] = [
|
$metrics[] = [
|
||||||
|
|
Loading…
Reference in a new issue