Set multiple retries with lighter lock & Send 409 in case of deadlock

This commit is contained in:
Bubka 2025-02-24 15:13:13 +01:00
parent 19f3a71c03
commit c8b5bd32a6
2 changed files with 4 additions and 2 deletions

View File

@ -107,6 +107,8 @@ class GroupController extends Controller
$group->loadCount('twofaccounts');
} catch (ModelNotFoundException $exc) {
abort(404);
} catch (\Throwable $th) {
abort(409, 'Conflict');
}
return new GroupResource($group);

View File

@ -59,7 +59,7 @@ class GroupService
$ids = is_array($ids) ? $ids : [$ids];
DB::transaction(function () use ($group, $ids, $user) {
$group = Group::lockForUpdate()->find($group->id);
$group = Group::sharedLock()->find($group->id);
$twofaccounts = TwoFAccount::sharedLock()->find($ids);
if (! $group) {
@ -73,7 +73,7 @@ class GroupService
$group->twofaccounts()->saveMany($twofaccounts);
Log::info(sprintf('Twofaccounts #%s assigned to group %s (ID #%s)', implode(',', $ids), var_export($group->name, true), $group->id));
});
}, 5);
} else {
Log::info('Cannot find a group to assign the TwoFAccounts to');
}