Bulk update context to prevent cache thrashing
This commit is contained in:
parent
1f461ac79a
commit
1a5737478f
|
|
@ -131,11 +131,15 @@ class InvoicePay extends Component
|
|||
#[On('payment-method-selected')]
|
||||
public function paymentMethodSelected($company_gateway_id, $gateway_type_id, $amount)
|
||||
{
|
||||
$this->setContext('company_gateway_id', $company_gateway_id);
|
||||
$this->setContext('gateway_type_id', $gateway_type_id);
|
||||
$this->setContext('amount', $amount);
|
||||
$this->setContext('pre_payment', false);
|
||||
$this->setContext('is_recurring', false);
|
||||
|
||||
$this->bulkSetContext([
|
||||
'company_gateway_id' => $company_gateway_id,
|
||||
'gateway_type_id' => $gateway_type_id,
|
||||
'amount' => $amount,
|
||||
'pre_payment' => false,
|
||||
'is_recurring' => false,
|
||||
]);
|
||||
|
||||
|
||||
$this->payment_method_accepted = true;
|
||||
|
||||
|
|
@ -236,10 +240,14 @@ class InvoicePay extends Component
|
|||
|
||||
$client = $invite->contact->client;
|
||||
$settings = $client->getMergedSettings();
|
||||
$this->setContext('contact', $invite->contact); // $this->context['contact'] = $invite->contact;
|
||||
$this->setContext('settings', $settings); // $this->context['settings'] = $settings;
|
||||
$this->setContext('db', $this->db); // $this->context['db'] = $this->db;
|
||||
$this->setContext('invitation_id', $this->invitation_id);
|
||||
|
||||
$this->bulkSetContext([
|
||||
'contact' => $invite->contact,
|
||||
'settings' => $settings,
|
||||
'db' => $this->db,
|
||||
'invitation_id' => $this->invitation_id,
|
||||
]);
|
||||
|
||||
|
||||
$invoices = Invoice::withTrashed()
|
||||
->whereIn('id', $this->transformKeys($this->invoices))
|
||||
|
|
@ -262,11 +270,6 @@ class InvoicePay extends Component
|
|||
$this->under_over_payment = $settings->client_portal_allow_over_payment || $settings->client_portal_allow_under_payment;
|
||||
$this->required_fields = false;
|
||||
|
||||
$this->setContext('variables', $this->variables); // $this->context['variables'] = $this->variables;
|
||||
$this->setContext('invoices', $invoices); // $this->context['invoices'] = $invoices;
|
||||
$this->setContext('settings', $settings); // $this->context['settings'] = $settings;
|
||||
// $this->setContext('invitation', $invite->withoutRelations()); // $this->context['invitation'] = $invite;
|
||||
|
||||
$payable_invoices = $invoices->map(function ($i) {
|
||||
/** @var \App\Models\Invoice $i */
|
||||
return [
|
||||
|
|
@ -281,8 +284,14 @@ class InvoicePay extends Component
|
|||
];
|
||||
})->toArray();
|
||||
|
||||
$this->setContext('amount', array_sum(array_column($payable_invoices, 'amount')));
|
||||
$this->setContext('payable_invoices', $payable_invoices);
|
||||
$this->bulkSetContext([
|
||||
'variables' => $this->variables,
|
||||
'invoices' => $invoices,
|
||||
'settings' => $settings,
|
||||
'amount' => array_sum(array_column($payable_invoices, 'amount')),
|
||||
'payable_invoices' => $payable_invoices,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function render(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
|
|
|
|||
|
|
@ -63,8 +63,10 @@ class ProcessPayment extends Component
|
|||
$gateway_fee = data_get($responder_data, 'payload.total.fee_total', false);
|
||||
$amount = data_get($responder_data, 'payload.total.amount_with_fee', 0);
|
||||
|
||||
$this->setContext('amount', $amount);
|
||||
$this->setContext('gateway_fee', $gateway_fee);
|
||||
$this->bulkSetContext([
|
||||
'amount' => $amount,
|
||||
'gateway_fee' => $gateway_fee,
|
||||
]);
|
||||
|
||||
$this->dispatch('payment-view-rendered');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,6 +52,20 @@ trait WithSecureContext
|
|||
return $clone;
|
||||
}
|
||||
|
||||
public function bulkSetContext(array $data): array
|
||||
{
|
||||
|
||||
$clone = $this->getContext();
|
||||
$clone = array_merge($clone, $data);
|
||||
|
||||
\Illuminate\Support\Facades\Cache::put(session()->getId(), $clone, now()->addHour());
|
||||
|
||||
$this->dispatch(self::CONTEXT_UPDATE);
|
||||
|
||||
return $clone;
|
||||
|
||||
}
|
||||
|
||||
public function resetContext(): void
|
||||
{
|
||||
\Illuminate\Support\Facades\Cache::forget(session()->getId());
|
||||
|
|
|
|||
Loading…
Reference in New Issue