mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 09:28:40 +00:00
optimised the memory usage by resource aggregation
This commit is contained in:
parent
e2575e7360
commit
bef0aff7c9
1 changed files with 37 additions and 29 deletions
|
|
@ -322,7 +322,34 @@ class Migrations extends Action
|
||||||
$migration->setAttribute('statusCounters', json_encode($transfer->getStatusCounters()));
|
$migration->setAttribute('statusCounters', json_encode($transfer->getStatusCounters()));
|
||||||
|
|
||||||
if (!empty($resources)) {
|
if (!empty($resources)) {
|
||||||
$aggregatedResources[] = $resources;
|
/**
|
||||||
|
* @var Resource $resource
|
||||||
|
*/
|
||||||
|
$resource = $resources[0];
|
||||||
|
$count = count($resources);
|
||||||
|
$databaseId = null;
|
||||||
|
$tableId = null;
|
||||||
|
switch ($resource->getName()) {
|
||||||
|
case ResourceTable::getName():
|
||||||
|
/** @var ResourceTable $resource */
|
||||||
|
$databaseId = $resource->getDatabase()->getSequence();
|
||||||
|
break;
|
||||||
|
case ResourceRow::getName():
|
||||||
|
/** @var ResourceRow $resource */
|
||||||
|
$table = $resource->getTable();
|
||||||
|
$databaseId = $table->getDatabase()->getSequence();
|
||||||
|
$tableId = $table->getSequence();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$aggregatedResources[] = [
|
||||||
|
"name" => $resource->getName(),
|
||||||
|
"count" => $count,
|
||||||
|
"databaseId" => $databaseId,
|
||||||
|
"tableId" => $tableId
|
||||||
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
$this->updateMigrationDocument($migration, $projectDocument, $queueForRealtime);
|
$this->updateMigrationDocument($migration, $projectDocument, $queueForRealtime);
|
||||||
},
|
},
|
||||||
|
|
@ -442,14 +469,12 @@ class Migrations extends Action
|
||||||
|
|
||||||
private function processMigrationResourceStats(array $resources, StatsUsage $queueForStatsUsage, Document $projectDocument, string $source, ?string $resourceId)
|
private function processMigrationResourceStats(array $resources, StatsUsage $queueForStatsUsage, Document $projectDocument, string $source, ?string $resourceId)
|
||||||
{
|
{
|
||||||
/**
|
$resourceName = $resources['name'];
|
||||||
* @var Resource $resource
|
$count = $resources['count'];
|
||||||
*/
|
$databaseInternalId = $resources['databaseId'];
|
||||||
$resource = $resources[0];
|
$tableInternalId = $resources['tableId'];
|
||||||
|
|
||||||
$databaseInternalId = null;
|
if ($source === CSV::getName()) {
|
||||||
$tableInternalId = null;
|
|
||||||
if ($source === CSV::getName() && !empty($resourceId)) {
|
|
||||||
[$databaseId, $tableId] = explode(':', $resourceId);
|
[$databaseId, $tableId] = explode(':', $resourceId);
|
||||||
$database = AuthorizationValidator::skip(fn () => $this->dbForProject->getDocument('databases', $databaseId));
|
$database = AuthorizationValidator::skip(fn () => $this->dbForProject->getDocument('databases', $databaseId));
|
||||||
$table = AuthorizationValidator::skip(fn () => $this->dbForProject->getDocument('database_' . $database->getSequence(), $tableId));
|
$table = AuthorizationValidator::skip(fn () => $this->dbForProject->getDocument('database_' . $database->getSequence(), $tableId));
|
||||||
|
|
@ -457,49 +482,32 @@ class Migrations extends Action
|
||||||
$tableInternalId = (int) $table->getSequence();
|
$tableInternalId = (int) $table->getSequence();
|
||||||
}
|
}
|
||||||
|
|
||||||
$count = count($resources);
|
switch ($resourceName) {
|
||||||
|
|
||||||
switch ($resource->getName()) {
|
|
||||||
case ResourceDatabase::getName():
|
case ResourceDatabase::getName():
|
||||||
$queueForStatsUsage->addMetric(METRIC_DATABASES, $count);
|
$queueForStatsUsage->addMetric(METRIC_DATABASES, $count);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ResourceTable::getName():
|
case ResourceTable::getName():
|
||||||
/** @var ResourceTable $resource */
|
|
||||||
$dbSeq = ($source === CSV::getName() && !empty($databaseInternalId))
|
|
||||||
? (int) $databaseInternalId
|
|
||||||
: (int) $resource->getDatabase()->getSequence();
|
|
||||||
|
|
||||||
$queueForStatsUsage
|
$queueForStatsUsage
|
||||||
->addMetric(METRIC_COLLECTIONS, $count)
|
->addMetric(METRIC_COLLECTIONS, $count)
|
||||||
->addMetric(
|
->addMetric(
|
||||||
str_replace('{databaseInternalId}', $dbSeq, METRIC_DATABASE_ID_COLLECTIONS),
|
str_replace('{databaseInternalId}', $databaseInternalId, METRIC_DATABASE_ID_COLLECTIONS),
|
||||||
$count
|
$count
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ResourceRow::getName():
|
case ResourceRow::getName():
|
||||||
/** @var ResourceRow $resource */
|
|
||||||
|
|
||||||
$table = $resource->getTable();
|
|
||||||
$dbSeq = ($source === CSV::getName() && !empty($databaseInternalId))
|
|
||||||
? (int) $databaseInternalId
|
|
||||||
: (int) $table->getDatabase()->getSequence();
|
|
||||||
$colSeq = ($source === CSV::getName() && !empty($tableInternalId))
|
|
||||||
? (int) $tableInternalId
|
|
||||||
: (int) $table->getSequence();
|
|
||||||
|
|
||||||
$queueForStatsUsage
|
$queueForStatsUsage
|
||||||
->addMetric(
|
->addMetric(
|
||||||
str_replace(
|
str_replace(
|
||||||
['{databaseInternalId}','{collectionInternalId}'],
|
['{databaseInternalId}','{collectionInternalId}'],
|
||||||
[$dbSeq, $colSeq],
|
[$databaseInternalId, $tableInternalId],
|
||||||
METRIC_DATABASE_ID_COLLECTION_ID_DOCUMENTS
|
METRIC_DATABASE_ID_COLLECTION_ID_DOCUMENTS
|
||||||
),
|
),
|
||||||
$count
|
$count
|
||||||
)
|
)
|
||||||
->addMetric(
|
->addMetric(
|
||||||
str_replace('{databaseInternalId}', $dbSeq, METRIC_DATABASE_ID_DOCUMENTS),
|
str_replace('{databaseInternalId}', $databaseInternalId, METRIC_DATABASE_ID_DOCUMENTS),
|
||||||
$count
|
$count
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue