• 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


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 ?

		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'))


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.