From 397717e9bc51f6aa63df471530933ee0154c5c2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Tue, 17 Mar 2026 18:21:17 +0800 Subject: [PATCH] =?UTF-8?q?refactor(lock):=20BatchDispatchLock=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0makeKey=E4=B8=8EgetExistingValue=E4=BE=BF=E4=BA=8E?= =?UTF-8?q?=E5=A4=8D=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Support/BatchDispatchLock.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/app/Support/BatchDispatchLock.php b/app/Support/BatchDispatchLock.php index 14f8c90..e973bd5 100644 --- a/app/Support/BatchDispatchLock.php +++ b/app/Support/BatchDispatchLock.php @@ -22,10 +22,28 @@ class BatchDispatchLock int $ttlSeconds = 60, string $value = '1', ): bool { - $orderIds = array_values(array_map('intval', $orderIds)); - - $lockKey = $namespace . ':' . md5($scope . '|' . $filterSummary . '|' . implode(',', $orderIds) . '|' . $limit); + $lockKey = static::makeKey($namespace, $scope, $filterSummary, $orderIds, $limit); return Cache::add($lockKey, $value, $ttlSeconds); } + + /** + * @param int[] $orderIds + */ + public static function makeKey( + string $namespace, + string $scope, + string $filterSummary, + array $orderIds, + int $limit, + ): string { + $orderIds = array_values(array_map('intval', $orderIds)); + + return $namespace . ':' . md5($scope . '|' . $filterSummary . '|' . implode(',', $orderIds) . '|' . $limit); + } + + public static function getExistingValue(string $lockKey): mixed + { + return Cache::get($lockKey); + } }