XF 2.1 How to optimize thread listing page with almost 1.5M thread in forum?

sajal

Active member
We've created different forums on our site and one of them contains around 1.5M threads. And we do have a threads per page limit is 25. So, it'll have total pages around 62000. Now, there's a problem, when you go deep into pages like say I have accessed 10000th page, the query which is prepared for this page is taking literally hundreds of seconds to execute:

SQL:
# Query_time: 972.392221  Lock_time: 0.000087 Rows_sent: 25  Rows_examined: 4717670

SELECT `xf_thread`.*, `xf_user_User_1`.*, `xf_user_LastPoster_2`.*
            FROM `xf_thread`
            LEFT JOIN `xf_user` AS `xf_user_User_1` ON (`xf_user_User_1`.`user_id` = `xf_thread`.`user_id`)
LEFT JOIN `xf_user` AS `xf_user_LastPoster_2` ON (`xf_user_LastPoster_2`.`user_id` = `xf_thread`.`last_post_user_id`)
            WHERE (`xf_thread`.`node_id` = 2) AND ((`xf_thread`.`discussion_state` IN ('visible'))) AND (`xf_thread`.`sticky` = 0)
            ORDER BY `xf_thread`.`last_post_date` DESC
     
LIMIT 25 OFFSET 1029575;

Please note that we've also 115000 users in xf_user table too. As you can see in the above query, to just read 25 rows, it has examined almost 5M rows!!

As you can see the OFFSET starts very deep. This is Core XF stuff, so I believe indexes are already created properly? Is there anything I could do? Since, this increases a LOT OF load on my AWS DB server and my DB instance is like 100%.

Any help appreciated.
 
Last edited:

That will help significantly, but not "solve" the problem - this would need a different scheme to basically get rid of ORDER BY with large offsets
 
One of our forums has over 254,000 threads in it (over 10,400 pages), but the delay is only about 5-6 seconds to display when I go deep into the pages. Should I be worried about this? I don't see that it's a big issue yet, but I've also seen our database hit the wall on performance (back when we used vBulletin, when we would run out of memory and start swapping to disk).

Only asking because it could come down to us splitting up this forum in the (near) future. And I have to admit that with the way just about everyone accesses the forum, they use the forum's search feature rather than browse back 10,000+ pages of threads.
 
Last edited:
Back
Top Bottom