I built a restaurant management app for a client using livewire. And today they made a complaint saying that the app responds too slowly. What it does is basically;
Click a button to select a category.
Livewire makes a query and gets all products of that category and shows their names on the screen (4-10 products for each (5) category)
The whole code looks like this :
public function selectCategory($categoryId)
{
if ($categoryId == $this->selectedCategory){
$this->selectedProduct = '';
$this->selectedCategory = '';
$this->products = [];
}else{
$this->selectedProduct = '';
$this->selectedCategory = $categoryId;
$this->products = Category::find($categoryId)->products;
$this->fields = Category::find($categoryId)->fields; // currently it only has 1 record that belongs to 1 category
}
}
As you can see there's not much going on, but when I inspect the requests on the network tab, I see each of them taking somewhere between 1.5 to 3 seconds to load on button clicks. I'm guessing the problem is their hosting company and not the code, but I'm open to suggestions.