From b6d4386949e716c8ce30992369a522895d5fe599 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Thu, 23 Oct 2014 16:42:04 -0700 Subject: [PATCH] fixes #2269 --- app/models/post.rb | 6 ++---- app/models/tag.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index 45d14653b..dbe8e896f 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -437,12 +437,10 @@ class Post < ActiveRecord::Base decrement_tags = tag_array_was - tag_array increment_tags = tag_array - tag_array_was if increment_tags.any? - Tag.where(:name => increment_tags).update_all("post_count = post_count + 1") - Post.expire_cache_for_all(increment_tags) + Tag.delay(:queue => "default").increment_post_counts(increment_tags) end if decrement_tags.any? - Tag.where(:name => decrement_tags).update_all("post_count = post_count - 1") - Post.expire_cache_for_all(decrement_tags) + Tag.delay(:queue => "default").decrement_post_counts(decrement_tags) end Post.expire_cache_for_all([""]) if new_record? || id <= 100_000 end diff --git a/app/models/tag.rb b/app/models/tag.rb index 46f888425..ed8cd9d2e 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -47,6 +47,16 @@ class Tag < ActiveRecord::Base select("post_count").order("post_count DESC").first.post_count end end + + def increment_post_counts(tag_names) + Tag.where(:name => tag_names).update_all("post_count = post_count + 1") + Post.expire_cache_for_all(tag_names) + end + + def decrement_post_counts(tag_names) + Tag.where(:name => tag_names).update_all("post_count = post_count - 1") + Post.expire_cache_for_all(tag_names) + end end def real_post_count