hillcow's avatar

How to handle big database queries with pagination in Laravel 5

Hey,

say I had a forum with more than a million threads, how would I approach showing these threads with pagination ordered by a column 'hot' that includes an integer? I couldn't simply do Thread::orderBy('hot', 'desc')->paginate(20) since this query would have to go through the whole million threads.

Thank you very much!

0 likes
1 reply
jlrdw's avatar

When you use built-in pagination it retrieves only the 20 at a time in the database, like limit in mysql. They're articles on stack Overflow covering efficient pagination with a large result sets, as even the limit clause can start bogging down.

I'd break this down into newer post and have another section for all the post say over a year having a separate table with a link if you user wants to go there. That's just a suggestion.

Please or to participate in this conversation.