wire click livewire method responds slowly when there are other methods that have larger processing data

36 views Asked by At

I'm using livewire v2. I have a problem when calling a method in livewire feels slow because another method has a large data process, for example I have 2 methods. the first method is called methodSmallData() and the second method is methodLargeData().

The code example is as below:

This is controller livewire Show.php :

<?php
namespace App\Http\Livewire\SomeController;

class Show extends Component
{

public function render(){

$smallData = $this->methodSmallData();
$largeData = $this->methodLargeData();

return view('path_view',compact('smallData ','largeData '));

}

public function methodSmallData(){
dd('test how long this dd is displayed');
return Products::all();
}

public function methodLargeData(){

return LargeProducts::all();
}

}

This is view component of livewire show.blade.php

<div>
  <button wire:click='methodSmallData'>Small Data Product</button>
  <button wire:click='methodLargeData'>LargeData Product</button>
</div>

when I run it the first time there is no problem and the dd() function immediately displays the message in it, but when I click the button the second time and so on I get a long delay of about 23 seconds to be able to display the message in the dd() function in the method methodSmallData().

I want to prioritize the methodSmallData() method to run without waiting for the methodLargeData() method to finish so that the methodSmallData() method can directly hit dd() without having to delay or wait for the methodLargeData() method to finish. the point is I don't want to be made into 1 load of the same data even though it has different values, so it is more structured that has small data can be completed first without having to wait together.

I tried to remove methodLargeData() in reder() and it successfully displayed the dd() message without any delay. but the problem is I can't access methodLargeData() because I might give the data some filters so I put it in the render() method.

0

There are 0 answers