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

Explanation for updateCountersAfterDiscussionSave() in Forum DataWriter

Discussion in 'XenForo Development Discussions' started by Shadab, Nov 30, 2010.

  1. Shadab

    Shadab Well-Known Member

    In XenForo_DataWriter_Forum class, theres this method updateCountersAfterDiscussionSave() which gets called after a discussion is inserted/updated so that the parent node can update the denormalized data accordingly.

    I'm a bit confused as to why a separate call to updateLastPost() method, which executes 1 query to fetch the data, is needed. If I understand correctly, this only runs if the last_post_id or title fields have changed. But aren't the updated fields accessible directly from the $discussionDw ?

    PHP:
            else if ($discussionDw->get('discussion_state') == 'visible'
                
    && $discussionDw->getExisting('discussion_state') == 'visible'
                
    && $discussionDw->getExisting('last_post_id') == $this->get('last_post_id')
                && (
    $discussionDw->isChanged('last_post_id') || $discussionDw->isChanged('title'))
            )
            {
                
    $this->updateLastPost();
            }
     
  2. Mike

    Mike XenForo Developer Staff Member

    Trying to get my head around the logic there... :)

    I believe that is called when the last post of the thread that was listed as being the last post is deleted. (The previous if handles new inserts.) Since the last post is going to be an earlier time, we don't know if there's a different thread that should be showing up as the last post.
     
    Shadab likes this.

Share This Page