From 8773d19f2f843d50ba0f51df879f044f41ee1b48 Mon Sep 17 00:00:00 2001 From: Lloric Mayuga Garcia Date: Thu, 2 Jul 2026 13:57:32 +0800 Subject: [PATCH 1/3] fix: prevent race condition when response job runs before request job --- src/Jobs/RecordBarstoolJob.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Jobs/RecordBarstoolJob.php b/src/Jobs/RecordBarstoolJob.php index 48dc057..fe65fa4 100644 --- a/src/Jobs/RecordBarstoolJob.php +++ b/src/Jobs/RecordBarstoolJob.php @@ -37,9 +37,22 @@ public function uniqueId(): string public function handle(): void { - Barstool::query()->updateOrCreate( - ['uuid' => $this->uuid], - $this->data, - ); + if ($this->type === RecordingType::REQUEST) { + Barstool::create([ + 'uuid' => $this->uuid, + ...$this->data, + ]); + return; + } + + $barstool = Barstool::where('uuid', $this->uuid) + ->first(); + + if ($barstool === null) { + $this->release(2); + return; + } + + $barstool->update($this->data); } } From 438929bc29a54cf8b3f361cae73f86b47c13dd71 Mon Sep 17 00:00:00 2001 From: Lloric Mayuga Garcia Date: Thu, 2 Jul 2026 14:09:26 +0800 Subject: [PATCH 2/3] Fixing phpstan --- src/Jobs/RecordBarstoolJob.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Jobs/RecordBarstoolJob.php b/src/Jobs/RecordBarstoolJob.php index fe65fa4..a4981bb 100644 --- a/src/Jobs/RecordBarstoolJob.php +++ b/src/Jobs/RecordBarstoolJob.php @@ -38,18 +38,20 @@ public function uniqueId(): string public function handle(): void { if ($this->type === RecordingType::REQUEST) { - Barstool::create([ - 'uuid' => $this->uuid, - ...$this->data, - ]); + Barstool::query() + ->create([ + 'uuid' => $this->uuid, + ...$this->data, + ]); return; } - $barstool = Barstool::where('uuid', $this->uuid) + $barstool = Barstool::query() + ->where('uuid', $this->uuid) ->first(); - if ($barstool === null) { - $this->release(2); + if ($barstool === null) { + $this->release(2); return; } From 0d6d8b6bd5e6a9378132f2b3732238af4947803c Mon Sep 17 00:00:00 2001 From: Lloric Mayuga Garcia Date: Thu, 2 Jul 2026 14:15:14 +0800 Subject: [PATCH 3/3] Refine data parameter type hint in constructortry to fix phpstan Update constructor parameter type hint for data. --- src/Jobs/RecordBarstoolJob.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Jobs/RecordBarstoolJob.php b/src/Jobs/RecordBarstoolJob.php index a4981bb..bc29da9 100644 --- a/src/Jobs/RecordBarstoolJob.php +++ b/src/Jobs/RecordBarstoolJob.php @@ -21,8 +21,9 @@ class RecordBarstoolJob implements ShouldBeUnique, ShouldQueue public int $uniqueFor = 60; + /** - * @param array $data + * @param array, mixed> $data */ public function __construct( public readonly RecordingType $type,