Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

#632 - More efficient way of updating the post count.

  • Loading branch information...
commit 5f63ac3ae6d707f8e7bf8b30b6234e1e1437abe1 1 parent 7c039f0
@oldskool oldskool authored
Showing with 1 addition and 5 deletions.
  1. +1 −5 post.php
View
6 post.php
@@ -191,12 +191,8 @@
$new_pid = $db->insert_id();
}
- // Count number of replies in the topic
- $result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'posts WHERE topic_id='.$tid) or error('Unable to fetch post count for topic', __FILE__, __LINE__, $db->error());
- $num_replies = $db->result($result, 0) - 1;
-
// Update topic
- $db->query('UPDATE '.$db->prefix.'topics SET num_replies='.$num_replies.', last_post='.$now.', last_post_id='.$new_pid.', last_poster=\''.$db->escape($username).'\' WHERE id='.$tid) or error('Unable to update topic', __FILE__, __LINE__, $db->error());
+ $db->query('UPDATE '.$db->prefix.'topics SET num_replies=num_replies+1, last_post='.$now.', last_post_id='.$new_pid.', last_poster=\''.$db->escape($username).'\' WHERE id='.$tid) or error('Unable to update topic', __FILE__, __LINE__, $db->error());
update_search_index('post', $new_pid, $message);

2 comments on commit 5f63ac3

@franzliedke

I really do wonder why they didn't do it this way originally. Maybe to have an extra layer of synchronization, as the database schema is not properly normalized? But then, really, what could happen that we introduce inconsistencies in the database, eh?

@nealpoole
Collaborator

The change was made when developing 1.2:

http://punbb.informer.com/forums/post/20715/#p20715

Rewrote topic reply counting code to be less error prone. The reply count for a topic is now re-calculated whenever a post is added or removed.

But making the UPDATE query relative to the current value (as this change does) is actually the correct way to do things, assuming every other script similarly keeps data in sync.

Please sign in to comment.
Something went wrong with that request. Please try again.