Coalesce duplicate cache calls into a single one per method

This commit is contained in:
David Bomba 2025-01-24 16:27:51 +11:00
parent 1a5737478f
commit ffd26b91a6
6 changed files with 55 additions and 37 deletions

View File

@ -31,21 +31,26 @@ class InvoiceSummary extends Component
public function mount()
{
$contact = $this->getContext()['contact'] ?? auth()->guard('contact')->user();
$this->invoices = $this->getContext()['payable_invoices'];
$this->amount = Number::formatMoney($this->getContext()['amount'], $contact->client);
$this->gateway_fee = isset($this->getContext()['gateway_fee']) ? Number::formatMoney($this->getContext()['gateway_fee'], $contact->client) : false;
$_context = $this->getContext();
$contact = $_context['contact'] ?? auth()->guard('contact')->user();
$this->invoices = $_context['payable_invoices'];
$this->amount = Number::formatMoney($_context['amount'], $contact->client);
$this->gateway_fee = isset($_context['gateway_fee']) ? Number::formatMoney($_context['gateway_fee'], $contact->client) : false;
}
#[On(self::CONTEXT_UPDATE)]
public function onContextUpdate(): void
{
$_context = $this->getContext();
// refactor logic for updating the price for eg if it changes with under/over pay
$contact = $this->getContext()['contact'] ?? auth()->guard('contact')->user();
$this->invoices = $this->getContext()['payable_invoices'];
$this->amount = Number::formatMoney($this->getContext()['amount'], $contact->client);
$this->gateway_fee = isset($this->getContext()['gateway_fee']) ? Number::formatMoney($this->getContext()['gateway_fee'], $contact->client) : false;
$contact = $_context['contact'] ?? auth()->guard('contact')->user();
$this->invoices = $_context['payable_invoices'];
$this->amount = Number::formatMoney($_context['amount'], $contact->client);
$this->gateway_fee = isset($_context['gateway_fee']) ? Number::formatMoney($_context['gateway_fee'], $contact->client) : false;
}
@ -53,18 +58,22 @@ class InvoiceSummary extends Component
public function handlePaymentViewRendered()
{
$contact = $this->getContext()['contact'] ?? auth()->guard('contact')->user();
$this->amount = Number::formatMoney($this->getContext()['amount'], $contact->client);
$this->gateway_fee = isset($this->getContext()['gateway_fee']) ? Number::formatMoney($this->getContext()['gateway_fee'], $contact->client) : false;
$_context = $this->getContext();
$contact = $_context['contact'] ?? auth()->guard('contact')->user();
$this->amount = Number::formatMoney($_context['amount'], $contact->client);
$this->gateway_fee = isset($_context['gateway_fee']) ? Number::formatMoney($_context['gateway_fee'], $contact->client) : false;
}
public function downloadDocument($invoice_hashed_id)
{
$invitation_id = $this->getContext()['invitation_id'];
$_context = $this->getContext();
$db = $this->getContext()['db'];
$invitation_id = $_context['invitation_id'];
$db = $_context['db'];
$invite = \App\Models\InvoiceInvitation::on($db)->withTrashed()->find($invitation_id);

View File

@ -56,12 +56,13 @@ class PaymentMethod extends Component
public function mount()
{
$this->variables = $this->getContext()['variables'];
$this->amount = array_sum(array_column($this->getContext()['payable_invoices'], 'amount'));
$_context = $this->getContext();
$this->variables = $_context['variables'];
$this->amount = array_sum(array_column($_context['payable_invoices'], 'amount'));
MultiDB::setDb($this->getContext()['db']);
MultiDB::setDb($_context['db']);
$contact = $this->getContext()['contact'] ?? auth()->guard('contact')->user();
$contact = $_context['contact'] ?? auth()->guard('contact')->user();
$this->methods = $contact->client->service()->getPaymentMethods($this->amount);

View File

@ -37,12 +37,14 @@ class ProcessPayment extends Component
$invitation = InvoiceInvitation::find($this->getContext()['invitation_id']);
$_context = $this->getContext();
$data = [
'company_gateway_id' => $this->getContext()['company_gateway_id'],
'payment_method_id' => $this->getContext()['gateway_type_id'],
'payable_invoices' => $this->getContext()['payable_invoices'],
'signature' => isset($this->getContext()['signature']) ? $this->getContext()['signature'] : false,
'signature_ip' => isset($this->getContext()['signature_ip']) ? $this->getContext()['signature_ip'] : false,
'company_gateway_id' => $_context['company_gateway_id'],
'payment_method_id' => $_context['gateway_type_id'],
'payable_invoices' => $_context['payable_invoices'],
'signature' => isset($_context['signature']) ? $_context['signature'] : false,
'signature_ip' => isset($_context['signature_ip']) ? $_context['signature_ip'] : false,
'pre_payment' => false,
'frequency_id' => false,
'remaining_cycles' => false,
@ -52,7 +54,7 @@ class ProcessPayment extends Component
$responder_data = (new LivewireInstantPayment($data))->run();
$company_gateway = CompanyGateway::find($this->getContext()['company_gateway_id']);
$company_gateway = CompanyGateway::find($_context['company_gateway_id']);
if (!$responder_data['success']) {
throw new PaymentFailed($responder_data['error'], 400);

View File

@ -56,17 +56,19 @@ class RequiredFields extends Component
public function mount(): void
{
$_context = $this->getContext();
MultiDB::setDB(
$this->getContext()['db'],
$_context['db'],
);
$this->fields = $this->getContext()['fields'];
$this->fields = $_context['fields'];
$contact = auth()->guard('contact')->user();
$this->company_gateway = CompanyGateway::withTrashed()
->with('company')
->find($this->getContext()['company_gateway_id']);
->find($_context['company_gateway_id']);
$this->client_name = $contact->client->name;
$this->contact_first_name = $contact->first_name;
@ -89,8 +91,8 @@ class RequiredFields extends Component
$this->client_custom_value4 = $contact->client->custom_value4;
$rff = new RFFService(
fields: $this->getContext()['fields'],
database: $this->getContext()['db'],
fields: $_context['fields'],
database: $_context['db'],
company_gateway_id: (string)$this->company_gateway->id,
);

View File

@ -30,10 +30,11 @@ class Terms extends Component
#[Computed()]
public function invoice()
{
$_context = $this->getContext();
$invitation_id = $this->getContext()['invitation_id'];
$invitation_id = $_context['invitation_id'];
$db = $this->getContext()['db'];
$db = $_context['db'];
$invite = \App\Models\InvoiceInvitation::on($db)->withTrashed()->find($invitation_id);

View File

@ -32,20 +32,23 @@ class UnderOverPayment extends Component
public function mount()
{
$contact = $this->getContext()['contact'] ?? auth()->guard('contact')->user();
$this->invoice_amount = array_sum(array_column($this->getContext()['payable_invoices'], 'amount'));
$_context = $this->getContext();
$contact = $_context['contact'] ?? auth()->guard('contact')->user();
$this->invoice_amount = array_sum(array_column($_context['payable_invoices'], 'amount'));
$this->currency = $contact->client->currency();
$this->payableInvoices = $this->getContext()['payable_invoices'];
$this->payableInvoices = $_context['payable_invoices'];
}
public function checkValue(array $payableInvoices)
{
$this->errors = '';
$_context = $this->getContext();
$settings = $_context['settings'];
$settings = $this->getContext()['settings'];
$contact = $this->getContext()['contact'] ?? auth()->guard('contact')->user();
$contact = $_context['contact'] ?? auth()->guard('contact')->user();
foreach ($payableInvoices as $key => $invoice) {
$payableInvoices[$key]['amount'] = Number::parseFloat($invoice['formatted_amount']);