mirror of
https://github.com/appwrite/appwrite
synced 2026-05-23 00:49:02 +00:00
Delete with worker
This commit is contained in:
parent
1403868d05
commit
38dc92bfa7
2 changed files with 17 additions and 28 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Appwrite\Platform\Modules\Databases\Http\Databases\Transactions;
|
||||
|
||||
use Appwrite\Event\Delete as DeleteEvent;
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\SDK\AuthType;
|
||||
use Appwrite\SDK\ContentType;
|
||||
|
|
@ -9,7 +10,6 @@ use Appwrite\SDK\Method;
|
|||
use Appwrite\SDK\Response as SDKResponse;
|
||||
use Appwrite\Utopia\Response as UtopiaResponse;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Database\Validator\UID;
|
||||
use Utopia\Swoole\Response as SwooleResponse;
|
||||
|
||||
|
|
@ -51,10 +51,11 @@ class Delete extends Action
|
|||
->param('transactionId', '', new UID(), 'Transaction ID.')
|
||||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
->inject('queueForDeletes')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(string $transactionId, UtopiaResponse $response, Database $dbForProject): void
|
||||
public function action(string $transactionId, UtopiaResponse $response, Database $dbForProject, DeleteEvent $queueForDeletes): void
|
||||
{
|
||||
$transaction = $dbForProject->getDocument('transactions', $transactionId);
|
||||
|
||||
|
|
@ -62,13 +63,11 @@ class Delete extends Action
|
|||
throw new Exception(Exception::TRANSACTION_NOT_FOUND);
|
||||
}
|
||||
|
||||
if (!$dbForProject->deleteDocument('transactions', $transactionId)) {
|
||||
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove transaction from DB');
|
||||
}
|
||||
$dbForProject->deleteDocument('transactions', $transactionId);
|
||||
|
||||
$dbForProject->deleteDocuments('transactionLogs', [
|
||||
Query::equal('transactionInternalId', [$transaction->getSequence()]),
|
||||
]);
|
||||
$queueForDeletes
|
||||
->setType(DELETE_TYPE_DOCUMENT)
|
||||
->setDocument($transaction);
|
||||
|
||||
$response->noContent();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -333,8 +333,7 @@ class Update extends Action
|
|||
array $data,
|
||||
\DateTime $createdAt,
|
||||
array &$state
|
||||
): void
|
||||
{
|
||||
): void {
|
||||
if ($documentId && !isset($data['$id'])) {
|
||||
$data['$id'] = $documentId;
|
||||
}
|
||||
|
|
@ -358,8 +357,7 @@ class Update extends Action
|
|||
array $data,
|
||||
\DateTime $createdAt,
|
||||
array &$state
|
||||
): void
|
||||
{
|
||||
): void {
|
||||
$dependent = isset($state[$collectionId][$documentId]);
|
||||
|
||||
if ($dependent) {
|
||||
|
|
@ -397,8 +395,7 @@ class Update extends Action
|
|||
array $data,
|
||||
\DateTime $createdAt,
|
||||
array &$state
|
||||
): void
|
||||
{
|
||||
): void {
|
||||
$dependent = isset($state[$collectionId][$documentId]);
|
||||
|
||||
if ($dependent) {
|
||||
|
|
@ -428,8 +425,7 @@ class Update extends Action
|
|||
string $documentId,
|
||||
\DateTime $createdAt,
|
||||
array &$state
|
||||
): void
|
||||
{
|
||||
): void {
|
||||
$dependent = isset($state[$collectionId][$documentId]);
|
||||
|
||||
if ($dependent) {
|
||||
|
|
@ -461,8 +457,7 @@ class Update extends Action
|
|||
array $data,
|
||||
\DateTime $createdAt,
|
||||
array &$state
|
||||
): void
|
||||
{
|
||||
): void {
|
||||
$dependent = isset($state[$collectionId][$documentId]);
|
||||
|
||||
if ($dependent) {
|
||||
|
|
@ -499,8 +494,7 @@ class Update extends Action
|
|||
array $data,
|
||||
\DateTime $createdAt,
|
||||
array &$state
|
||||
): void
|
||||
{
|
||||
): void {
|
||||
$dependent = isset($state[$collectionId][$documentId]);
|
||||
|
||||
if ($dependent) {
|
||||
|
|
@ -536,8 +530,7 @@ class Update extends Action
|
|||
array $data,
|
||||
\DateTime $createdAt,
|
||||
array &$state
|
||||
): void
|
||||
{
|
||||
): void {
|
||||
$dbForProject->withRequestTimestamp($createdAt, function () use ($dbForProject, $collectionId, $data, &$state) {
|
||||
$dbForProject->createDocuments(
|
||||
$collectionId,
|
||||
|
|
@ -561,8 +554,7 @@ class Update extends Action
|
|||
array $data,
|
||||
\DateTime $createdAt,
|
||||
array &$state
|
||||
): void
|
||||
{
|
||||
): void {
|
||||
$queries = Query::parseQueries($data['queries'] ?? []);
|
||||
|
||||
$dbForProject->updateDocuments(
|
||||
|
|
@ -596,8 +588,7 @@ class Update extends Action
|
|||
array $data,
|
||||
\DateTime $createdAt,
|
||||
array &$state
|
||||
): void
|
||||
{
|
||||
): void {
|
||||
// Run bulk upsert without timestamp wrapper, checking manually in callback
|
||||
$dbForProject->upsertDocuments(
|
||||
$collectionId,
|
||||
|
|
@ -633,8 +624,7 @@ class Update extends Action
|
|||
array $data,
|
||||
\DateTime $createdAt,
|
||||
array &$state
|
||||
): void
|
||||
{
|
||||
): void {
|
||||
$queries = Query::parseQueries($data['queries'] ?? []);
|
||||
|
||||
$dbForProject->deleteDocuments(
|
||||
|
|
|
|||
Loading…
Reference in a new issue