Getting Popular Topics on a Custom Made Forum

Posted by Navarr on Stack Overflow See other posts from Stack Overflow or by Navarr
Published on 2010-06-08T22:32:15Z Indexed on 2010/06/08 22:52 UTC
Read the original article Hit count: 160

Filed under:
|
|
|

For this website we're working on, we're trying to get the most popular topics (based on how many posts have been made in them within the last 24 hours). We have a medium to large based forum, and the current MySQL query looks like this:

SELECT `forums_topics`.*,
(
    SELECT COUNT(`id`)
    FROM `forums_posts`
    WHERE `postdate` > (UNIX_TIMESTAMP()-60*60*24) 
    AND `topicid`=`forums_topics`.`id`
) AS `trendy_threads` 
FROM `forums_topics` 
WHERE `deleted`=0
ORDER BY `trendy_threads` DESC,`postdate` DESC
LIMIT 3

This unfortunately causes an SQL timeout with just one query and Error 500's.

How can we get this information as quickly and as efficiently as possible?

© Stack Overflow or respective owner

Related posts about php

Related posts about sql