Theoretical/Performance Question

Let's say I have a livewire component that's a list of items. The list has a foreach loop that iterates through livewire component items in the list. So something like this:
@foreach($list as $item)
<livewire:my-component ...
@endforeach
@foreach($list as $item)
<livewire:my-component ...
@endforeach
In the above scenario, which is generally going to be the most performant? 1) Pass in the ID of the item and query the database within the item component to get any add'l fields. 2) Pass in the entire $item. This would mean you're passing a much larger object, but you're not querying the database for each item. 3) Query once in the outer list component and pass in an array of only the necessary data elements to each item? I was doing #2 and having performance issues, so I moved to #1, also performance issues. I've also tried passing in each individual field that's needed, which is generally better performance-wise, but if I need almost all the fields on the object, then I'm passing in a ton of fields. How do you guys generally handle these types of challenges? Hitting some walls performance-wise with Filament and I feel confident it's my own lack of skills and not the framework itself.
Solution:
Definitely 3. Otherwise you’re going to have n+1 issues. But I say that not knowing the functionality of the repeated component.
Jump to solution
2 Replies
Solution
awcodes
awcodes4mo ago
Definitely 3. Otherwise you’re going to have n+1 issues. But I say that not knowing the functionality of the repeated component.
Jon Mason
Jon MasonOP4mo ago
ok, that's what I was thinking. Lots of code to refactor now lol.
Want results from more Discord servers?
Add your server