Skip to content

Commit 184e432

Browse files
committed
minimal speedup and deprecated the paid method.
1 parent 0b901b9 commit 184e432

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

phpstan-baseline.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ parameters:
66
path: src/Models/Wallet.php
77

88
-
9-
message: "#^Call to an undefined method Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\MorphMany\\:\\:where\\(\\)\\.$#"
9+
message: "#^Call to an undefined method Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\MorphMany\\:\\:with\\(\\)\\.$#"
1010
count: 1
1111
path: src/Services/PurchaseService.php
1212

src/Interfaces/CartInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
use Bavix\Wallet\Internal\Dto\BasketDtoInterface;
88
use Bavix\Wallet\Internal\Exceptions\CartEmptyException;
99

10+
/**
11+
* A kind of cart hydrate, needed for a smooth transition from a convenient dto to a less convenient internal dto.
12+
*/
1013
interface CartInterface
1114
{
1215
/**

src/Interfaces/Customer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,5 +194,10 @@ public function refundGiftCart(CartInterface $cart, bool $force = false): bool;
194194
*/
195195
public function forceRefundGiftCart(CartInterface $cart): bool;
196196

197+
/**
198+
* Checks acquired product your wallet.
199+
*
200+
* @deprecated The method is slow and will be removed in the future
201+
*/
197202
public function paid(Product $product, bool $gifts = false): ?Transfer;
198203
}

src/Services/PurchaseService.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ public function already(Customer $customer, BasketDtoInterface $basketDto, bool
2222
foreach ($basketDto->items() as $itemDto) {
2323
/** @var Model $product */
2424
$product = $itemDto->product();
25+
26+
/**
27+
* As part of my work, "with" was added, it gives a 50x boost for a huge number of returns. In this case,
28+
* it's a crutch. It is necessary to come up with a more correct implementation of the internal and external
29+
* interface for "purchases".
30+
*/
2531
$arrays[] = (clone $query)
32+
->with(['deposit', 'withdraw.wallet'])
2633
->where('to_type', $product->getMorphClass())
2734
->where('to_id', $product->getKey())
2835
->whereIn('status', $status)

src/Traits/CartPay.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,24 +184,20 @@ public function refundCart(CartInterface $cart, bool $force = false, bool $gifts
184184
);
185185
}
186186

187+
$index = 0;
187188
$objects = [];
189+
$transfers = array_values($transfers);
188190
$prepareService = app(PrepareServiceInterface::class);
189191
foreach ($cart->getBasketDto()->cursor() as $product) {
190-
$transfer = current($transfers);
191-
next($transfers);
192-
/**
193-
* the code is extremely poorly written, a complete refactoring is required. for version 6.x we will
194-
* leave it as it is.
195-
*/
196-
$transfer->load('withdraw.wallet'); // fixme: need optimize
197-
198192
$objects[] = $prepareService->transferLazy(
199193
$product,
200-
$transfer->withdraw->wallet,
194+
$transfers[$index]->withdraw->wallet,
201195
Transfer::STATUS_TRANSFER,
202-
$transfer->deposit->amount, // fixme: need optimize
196+
$transfers[$index]->deposit->amount,
203197
app(MetaServiceLegacy::class)->getMeta($cart, $product)
204198
);
199+
200+
++$index;
205201
}
206202

207203
if ($force === false) {
@@ -274,6 +270,8 @@ public function forceRefundGiftCart(CartInterface $cart): bool
274270

275271
/**
276272
* Checks acquired product your wallet.
273+
*
274+
* @deprecated The method is slow and will be removed in the future
277275
*/
278276
public function paid(Product $product, bool $gifts = false): ?Transfer
279277
{

0 commit comments

Comments
 (0)