fix regression with tag post counts

This commit is contained in:
r888888888
2013-05-06 18:15:27 -07:00
parent 890e11f532
commit 8ba43c8cd1
3 changed files with 27 additions and 16 deletions

View File

@@ -314,18 +314,24 @@ class Post < ActiveRecord::Base
end
def increment_tag_post_counts
Post.execute_sql("UPDATE tags SET post_count = post_count + 1 WHERE name IN (?)", tag_array) if tag_array.any?
Tag.update_all("post_count = post_count + 1", {:name => tag_array}) if tag_array.any?
end
def decrement_tag_post_counts
Post.execute_sql("UPDATE tags SET post_count = post_count - 1 WHERE name IN (?)", tag_array) if tag_array.any?
Tag.update_all("post_count = post_count - 1", {:name => tag_array}) if tag_array.any?
end
def update_tag_post_counts
decrement_tags = tag_array_was - tag_array
increment_tags = tag_array - tag_array_was
Post.expire_cache_for_all(decrement_tags) if decrement_tags.any?
Post.expire_cache_for_all(increment_tags) if increment_tags.any?
if increment_tags.any?
Tag.update_all("post_count = post_count + 1", {:name => increment_tags})
Post.expire_cache_for_all(increment_tags) if increment_tags.any?
end
if decrement_tags.any?
Tag.update_all("post_count = post_count - 1", {:name => decrement_tags})
Post.expire_cache_for_all(decrement_tags) if decrement_tags.any?
end
Post.expire_cache_for_all([""]) if new_record? || id <= 100_000
end