fix: use atomic operations for count updates
This commit is contained in:
parent
5d2d74e64d
commit
6c09d04038
|
@ -533,8 +533,8 @@ App::post('/v1/teams/:teamId/memberships')
|
||||||
} catch (Duplicate $th) {
|
} catch (Duplicate $th) {
|
||||||
throw new Exception(Exception::TEAM_INVITE_ALREADY_EXISTS);
|
throw new Exception(Exception::TEAM_INVITE_ALREADY_EXISTS);
|
||||||
}
|
}
|
||||||
$team->setAttribute('total', $team->getAttribute('total', 0) + 1);
|
|
||||||
$team = Authorization::skip(fn() => $dbForProject->updateDocument('teams', $team->getId(), $team));
|
Authorization::skip(fn() => $dbForProject->increaseDocumentAttribute('teams', $team->getId(), 'total', 1));
|
||||||
|
|
||||||
$dbForProject->deleteCachedDocument('users', $invitee->getId());
|
$dbForProject->deleteCachedDocument('users', $invitee->getId());
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -516,13 +516,8 @@ class Deletes extends Action
|
||||||
if ($document->getAttribute('confirm')) { // Count only confirmed members
|
if ($document->getAttribute('confirm')) { // Count only confirmed members
|
||||||
$teamId = $document->getAttribute('teamId');
|
$teamId = $document->getAttribute('teamId');
|
||||||
$team = $dbForProject->getDocument('teams', $teamId);
|
$team = $dbForProject->getDocument('teams', $teamId);
|
||||||
if (!$team->isEmpty()) {
|
if (!$team->isEmpty() && $team->getAttribute('total', 0) > 0) {
|
||||||
$team = $dbForProject->updateDocument(
|
$dbForProject->decreaseDocumentAttribute('teams', $teamId, 'total', 1);
|
||||||
'teams',
|
|
||||||
$teamId,
|
|
||||||
// Ensure that total >= 0
|
|
||||||
$team->setAttribute('total', \max($team->getAttribute('total', 0) - 1, 0))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue