app/models/topic.rb
# using count isn't ideal but it gives us correct caches each time
using count isn't ideal but it gives us correct caches each time
using count isn ' t ideal but it gives us correct caches each time
def update_forum_counter_cache
      forum_conditions = ['topics_count = ?', Topic.count(:id, :conditions => {:forum_id => forum_id})]
      if !frozen? && @old_forum_id && @old_forum_id != forum_id
        set_post_forum_id
        Forum.update_all ['topics_count = ?, forum_posts_count = ?', 
          Topic.count(:id, :conditions => {:forum_id => @old_forum_id}),
          ForumPost.count(:id, :conditions => {:forum_id => @old_forum_id})], ['id = ?', @old_forum_id]
      end
       or was deleted
      if frozen? || (@old_forum_id && @old_forum_id != forum_id)
        forum_conditions.first << ", forum_posts_count = ?"
        forum_conditions << ForumPost.count(:id, :conditions => {:forum_id => forum_id})
      end
      Forum.update_all forum_conditions, ['id = ?', forum_id]
      @old_forum_id = @voices = nil
    end
def update_forum_counter_cache forum_conditions = [ 'topics_count = ?' , Topic . count ( :id , :conditions => { :forum_id => forum_id } ) ] if ! frozen? && @old_forum_id && @old_forum_id != forum_id set_post_forum_id Forum . update_all [ 'topics_count = ?, forum_posts_count = ?' , Topic . count ( :id , :conditions => { :forum_id => @old_forum_id } ) , ForumPost . count ( :id , :conditions => { :forum_id => @old_forum_id } ) ] , [ 'id = ?' , @old_forum_id ] end if frozen? || ( @old_forum_id && @old_forum_id != forum_id ) forum_conditions . first << ", forum_posts_count = ?" forum_conditions << ForumPost . count ( :id , :conditions => { :forum_id => forum_id } ) end Forum . update_all forum_conditions , [ 'id = ?' , forum_id ] @old_forum_id = @voices = nil end
using count isn't ideal but it gives us correct caches each time
using count isn ' t ideal but it gives us correct caches each time
# if the topic moved forums # if the topic moved forums or was deleted