Slow action modal opening times on resource table
I have a GroupOrderManagementResource with a table, which has actions that use my GroupOrder model records in it's functions. Opening these actions seems to take too long (3+ secons), and I was wondering if I am doing something inefficiently when it comes to using the Resource model records in the table? So my Resource setup looks like this:
Then I define my table query like this:
Where I am wondering if I am using eager loading correctly?
And finally, I have a
note
TextColumn, that I have added an action to with a form to add/edit the note for a record:
Any insight is highly appreciated!
Thanks!21 Replies
use telescope and debug where the slowdown is
It might be worth it to share my
activeDayGroupOrders()
method from my GroupOrder model as well:
Thank you, will look into telescope, is it built into laravel?if you have. alot in the mealtype model, you could index deadline.
MealType is three records, breakfast, lunch and dinner
No it's a standard Debugger which will show the request and dig down on the request and what is slow
Or debugbar
ahh.. I have debugbar installed, but disabled. Will see what enabling it gives me, one sec.
Not sure where I should be looking in debugbar, but I also find the action being unreliable when clicking it and expecting the modal to open:
I also investigated the HTML in dev tools, where it looks like the javascript for clicking the action button is triggered, but somehow the action model does not open sometimes, is this a known bug in filament? Or is it unrelated to filament?
620 queries is cause for concern. Especially with eager loading
That's an awful lot! I would say look at this in mor defail, you are probably not putting closures in the selects..
Yes I always thought too much stuff was happening in the background. Can I expect that all these 620+ queries are due to this resource table, and I can focus on that only?
And what amount of queries should I aim for?
Try to keep a page load under 100 queries. But also the queries themselves should be efficient. Inefficient queries can cause issues in small numbers.
Can you provide your whole table code so we review
Yes of course! Thank you!
I thought it would be best to just share the whole php file for the resource.
It seems like most of the queries come from my
TextColumn::make('userOrders.userOrderItems.product_name')
, so that is probably the column that would benefit the most from proper eager loading. But I though I already eager loaded everything that column needs. Apparently not :/First thing first:
You shouldn't be calling a queried array of options like that. it should be:
That will reduce it straight away
TextColumn::make('userOrders.userOrderItems.product_name')
is heavy as, you are calling the product_name, then running a query after the function to find the SKU etc. You should have this as a relationship/join so that product_name is so:
userOrders.userOrderItems.product
and then the prodiuct should have the SKU, Type, Category etc. All preloading into the main query not more additional queries
Thank you!
Interestingly this:
gives me 661 queries, while this:
gives me 697 queries, so using the closure seems to increase the amount of queries, hmm..
This is before I have attempted to optimize the
TextColumn::make('userOrders.userOrderItems.product_name')
column.It looks complicated. Look like you try to get all in formation loaded in the table. Each table record will queries many many times. I would think that you should make another database table for this. If your data have been saved to another table like group_order_management, where they created final result. Then your model GroupOrderManagement and This resource will just load quickly in table.
Fairly sure you don't need the toArray() in a pluck method but could be wrong
I don't think it should be necessary with another table. It seems like I have reduced the queries to ~137 already by modifying my eager loading in the table query:
And using this relationship in my problematic
TextColumn
:
True, then this:
Gives me ~ 2 queries less than this:
Correct, a small improvement atleast.
Well done on the table query loading 😄
Thank you! I still have some improvements to do, especially with how I use the OrderStatus model, but this jump started my progress in optimizing my eloquent relationships and loading 🙂