1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Discussion about Hot Threads/Topics

Discussion in 'XenForo Development Discussions' started by robdog, Oct 10, 2011.

  1. robdog

    robdog Well-Known Member

    I had a plugin that I wrote for vBulletin and I wanted to move it over to XenForo. Basically, each thread would have a running point tally that would be cron'd at the end of week to determine the hot threads.
    • Registered User Thread View - 5 Points
    • Visitor Thread View - 1 Point
    • Thread Reply - 10 Points
    I would add 2 columns to the post table, post_hot_count(int) and post_hot_flg(bit).
    Display would be a XenPorta Block.
    Thoughts? (does this sound like the best approach?)
  2. xfrocks

    xfrocks Well-Known Member

    Probably that will kill the database if the site is busy.

    For the views, you can extends XenForo_Model_Thread and override updateThreadViews() to something like this

    public function updateThreadViews() {
    $db $this->_getDb();
    $updates $db->fetchPairs('
    SELECT thread_id, COUNT(*)
    FROM xf_thread_view
    GROUP BY thread_id
    foreach (
    $updates AS $threadId => $views) {
    $offset $views 5// change your weight here
    UPDATE xf_post SET
    post_hot_count = post_hot_count + ?
    WHERE thread_id = ?
    , array($offset$threadId));

    parent::updateThreadViews(); // let the parent do its job
    If you want to make the add-on aware of registered users and guests, you will have to override logThreadView() (in XenForo_Model_Thread) too. Then you can add one extra column in the `xf_thread_view` table to track it. Pretty complicated if you ask me :D

    About the reply, that one can be process in real time (increase the point when a new post is made) because people don't reply much. At least I hope so...

    PS: I'm not sure why the hot count is in the post table though :p

Share This Page