MyBB Community Forums

Full Version: Slow reply posting for long threads
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
A suggestion if wished to be implemented, or a guide to others otherwise.

Have been wondering why replying to a thread with a lot of posts was slow, and found out that the following two queries are rather time consuming:
SELECT pid FROM mybb_posts WHERE tid='x' ORDER BY dateline ASC LIMIT 0, 1
(various first post checks in inc/datahandlers/post.php)
SELECT u.uid, u.username, p.username AS postusername, p.dateline FROM mybb_posts p LEFT JOIN mybb_users u ON (u.uid=p.uid) WHERE p.tid='x' ORDER BY p.dateline ASC LIMIT 1
(from update_thread_data())

An index needs to be placed on tid,dateline, eg
ALTER TABLE mybb_posts ADD KEY tiddate(tid,dateline);

Also, in the update_forum_counters() function, a call to $cache->update_forums() is made - this appears to be unnecessary, since the only columns being updated are specifically ignored in $cache->update_forums() (with the exception of lastposttid and lastpostsubject, but my guess is that these two are never used without lastpost/lastposter/lastposteruid); note, I haven't double checked this.
As my forums cache is rather large, I've removed this call, shaving 1 second off the posting time.


The above changes resolved the issue for me.
Thought it may be useful to others to know.