Use a lengthaware, and first pass store count in session. Then page 2, 3, etc you don't need to count again.
Method paginate - Laravel
Good morning guys, I have a complex query that takes about 3 seconds to execute returning 113 thousand records with about 10 joins, etc, etc ...
So far ok, but because of paging it is as if we generated 2 queries one to know the total of records and the other to bring the records that would take 6 seconds ... After all the pagination does a count with the * of all tables which would be totally unnecessary because I use the paginate method ...
Would it be possible to make a custom pagination for this case? At first with some laravel feature even without using the traditional paginate ???
The intention would be to change the query that generates the count with * to count(0) because the * represents that I want to count all fields from all tables and would give this catastrophe, where if I pass a single field ready already solves, it drops from 3 seconds to 1 second ...
Does anyone have any suggestions ??? Thanks for now ...
@Dárcio Júnior If that solves your problem, please mark his answer as "Best answer" to close the discussion.
Please or to participate in this conversation.