1
0
Fork 0
mirror of synced 2024-06-03 11:24:48 +12:00

Merge pull request #1567 from appwrite/feat-delete-collection-attributes-indexes

feat(refactor-db): delete internal attributes and indexes on deleteCollection
This commit is contained in:
Eldad A. Fux 2021-09-19 23:18:39 +03:00 committed by GitHub
commit 45066d99db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 4 deletions

View file

@ -6,9 +6,10 @@ arch:
os: linux
# Small change
vm:
size: large
size: large
language: shell
notifications:

View file

@ -620,12 +620,15 @@ App::delete('/v1/database/collections/:collectionId')
throw new Exception('Collection not found', 404);
}
$dbForExternal->deleteCollection($collectionId); // TDOD move to DB worker
if (!$dbForInternal->deleteDocument('collections', $collectionId)) {
throw new Exception('Failed to remove collection from DB', 500);
}
$deletes
->setParam('type', DELETE_TYPE_DOCUMENT)
->setParam('document', $collection)
;
$usage->setParam('database.collections.delete', 1);
$events

View file

@ -44,6 +44,9 @@ class DeletesV1 extends Worker
switch ($document->getCollection()) {
// TODO@kodumbeats define these as constants somewhere
case 'collections':
$this->deleteCollection($document, $projectId);
break;
case 'projects':
$this->deleteProject($document);
break;
@ -92,6 +95,28 @@ class DeletesV1 extends Worker
{
}
/**
* @param Document $document teams document
* @param string $projectId
*/
protected function deleteCollection(Document $document, string $projectId): void
{
$collectionId = $document->getId();
$dbForInternal = $this->getInternalDB($projectId);
$dbForExternal = $this->getExternalDB($projectId);
$this->deleteByGroup('attributes', [
new Query('collectionId', Query::TYPE_EQUAL, [$collectionId])
], $dbForInternal);
$this->deleteByGroup('indexes', [
new Query('collectionId', Query::TYPE_EQUAL, [$collectionId])
], $dbForInternal);
$dbForExternal->deleteCollection($collectionId);
}
/**
* @param int $timestamp1d
* @param int $timestamp30m

View file

@ -403,5 +403,13 @@ class DatabaseCustomServerTest extends Scope
$this->assertEquals(400, $tooMany['headers']['status-code']);
$this->assertEquals('Index limit exceeded', $tooMany['body']['message']);
$collection = $this->client->call(Client::METHOD_DELETE, '/database/collections/' . $collectionId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]));
$this->assertEquals(204, $collection['headers']['status-code']);
}
}