Skip to content

Commit afc1697

Browse files
committed
fix: add db locks to prevent locks
1 parent 90d6839 commit afc1697

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/Models/AuditKey.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public static function createOrFind(array $keys): AuditKey
5454

5555
/** @var AuditKey $key */
5656
$key = AuditKey::query()
57+
->lockForUpdate()
5758
->firstOrCreate([
5859
'hash' => $jsonHash
5960
], [
@@ -62,4 +63,4 @@ public static function createOrFind(array $keys): AuditKey
6263

6364
return $key;
6465
}
65-
}
66+
}

src/Models/AuditModel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class AuditModel extends BaseModel
4343
public static function createOrFind(AuditActivity $activity, int $modelType, int $modelId): AuditModel
4444
{
4545
/** @var AuditModel $model */
46-
$model = AuditModel::query()->create([
46+
$model = AuditModel::query()->lockForUpdate()->create([
4747
'activity_id' => $activity->id,
4848
'entity_type' => $modelType,
4949
'entity_id' => $modelId,
@@ -65,4 +65,4 @@ public function entity()
6565
{
6666
return $this->morphTo();
6767
}
68-
}
68+
}

src/Models/AuditRoute.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public static function createOrFind(string $route): AuditRoute
4242
$routeHash = md5(strtolower(trim($route)));
4343

4444
/** @var AuditRoute $route */
45-
$route = AuditRoute::query()->firstOrCreate([
45+
$route = AuditRoute::query()->lockForUpdate()->firstOrCreate([
4646
'route_hash' => $routeHash,
4747
], [
4848
'route' => $route,
4949
]);
5050

5151
return $route;
5252
}
53-
}
53+
}

0 commit comments

Comments
 (0)