From 5fb1ab65f42a3154644a6b644f3359f7a8379d6c Mon Sep 17 00:00:00 2001 From: r888888888 Date: Thu, 18 Apr 2013 00:41:34 -0700 Subject: [PATCH] fixes --- app/models/post.rb | 9 ++++----- app/models/tag_alias.rb | 13 ++++--------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index 790ad1fbf..190a9e865 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -304,18 +304,18 @@ class Post < ActiveRecord::Base end def increment_tag_post_counts - execute_sql("UPDATE tags SET post_count = post_count + 1 WHERE name IN (?)", tag_array) if tag_array.any? + Post.execute_sql("UPDATE tags SET post_count = post_count + 1 WHERE name IN (?)", tag_array) if tag_array.any? end def decrement_tag_post_counts - execute_sql("UPDATE tags SET post_count = post_count - 1 WHERE name IN (?)", tag_array) if tag_array.any? + Post.execute_sql("UPDATE tags SET post_count = post_count - 1 WHERE name IN (?)", 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 - execute_sql("UPDATE tags SET post_count = post_count - 1 WHERE name IN (?)", decrement_tags) if decrement_tags.any? - execute_sql("UPDATE tags SET post_count = post_count + 1 WHERE name IN (?)", increment_tags) if increment_tags.any? + Post.execute_sql("UPDATE tags SET post_count = post_count - 1 WHERE name IN (?)", decrement_tags) if decrement_tags.any? + Post.execute_sql("UPDATE tags SET post_count = post_count + 1 WHERE name IN (?)", increment_tags) if increment_tags.any? Post.expire_cache_for_all(decrement_tags) if decrement_tags.any? Post.expire_cache_for_all(increment_tags) if increment_tags.any? Post.expire_cache_for_all([""]) if new_record? || id <= 100_000 @@ -612,7 +612,6 @@ class Post < ActiveRecord::Base votes.create(:score => score) else - puts "raising" raise PostVote::Error.new("You have already voted for this post") end end diff --git a/app/models/tag_alias.rb b/app/models/tag_alias.rb index ccadb95ff..9870a85d8 100644 --- a/app/models/tag_alias.rb +++ b/app/models/tag_alias.rb @@ -60,16 +60,11 @@ class TagAlias < ActiveRecord::Base include CacheMethods def self.to_aliased(names) - alias_hash = Cache.get_multi(names.flatten, "ta") do |name| - ta = TagAlias.find_by_antecedent_name(name) - if ta && ta.is_active? - ta.consequent_name - else - name + Array(names).flatten.map do |name| + Cache.get("ta:#{Cache.sanitize(name)}") do + ActiveRecord::Base.select_value_sql("select consequent_name from tag_aliases where status = 'active' and antecedent_name = ?", name) || name end - end - - alias_hash.values.flatten.uniq + end.uniq end def process!