Skip to content

Commit ff55230

Browse files
committed
optimize StorageServiceLockDecorator::increase
1 parent 83e7697 commit ff55230

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Internal/Decorator/StorageServiceLockDecorator.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Bavix\Wallet\Internal\Exceptions\LockProviderNotFoundException;
88
use Bavix\Wallet\Internal\Exceptions\RecordNotFoundException;
99
use Bavix\Wallet\Internal\Service\LockServiceInterface;
10+
use Bavix\Wallet\Internal\Service\MathServiceInterface;
1011
use Bavix\Wallet\Internal\Service\StateServiceInterface;
1112
use Bavix\Wallet\Internal\Service\StorageServiceInterface;
1213

@@ -15,7 +16,8 @@ final class StorageServiceLockDecorator implements StorageServiceInterface
1516
public function __construct(
1617
private StorageServiceInterface $storageService,
1718
private StateServiceInterface $stateService,
18-
private LockServiceInterface $lockService
19+
private LockServiceInterface $lockService,
20+
private MathServiceInterface $mathService
1921
) {
2022
}
2123

@@ -45,6 +47,11 @@ public function sync(string $uuid, float|int|string $value): bool
4547
*/
4648
public function increase(string $uuid, float|int|string $value): string
4749
{
48-
return $this->lockService->block($uuid, fn () => $this->storageService->increase($uuid, $value));
50+
return $this->lockService->block($uuid, function () use ($uuid, $value): string {
51+
$result = $this->mathService->add($this->get($uuid), $value);
52+
$this->sync($uuid, $result);
53+
54+
return $this->mathService->round($result);
55+
});
4956
}
5057
}

0 commit comments

Comments
 (0)