This commit is contained in:
r888888888
2013-04-18 00:41:34 -07:00
parent c9a95a59ae
commit 5fb1ab65f4
2 changed files with 8 additions and 14 deletions

View File

@@ -304,18 +304,18 @@ class Post < ActiveRecord::Base
end end
def increment_tag_post_counts 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 end
def decrement_tag_post_counts 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 end
def update_tag_post_counts def update_tag_post_counts
decrement_tags = tag_array_was - tag_array decrement_tags = tag_array_was - tag_array
increment_tags = tag_array - tag_array_was 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? Post.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 (?)", increment_tags) if increment_tags.any?
Post.expire_cache_for_all(decrement_tags) if decrement_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(increment_tags) if increment_tags.any?
Post.expire_cache_for_all([""]) if new_record? || id <= 100_000 Post.expire_cache_for_all([""]) if new_record? || id <= 100_000
@@ -612,7 +612,6 @@ class Post < ActiveRecord::Base
votes.create(:score => score) votes.create(:score => score)
else else
puts "raising"
raise PostVote::Error.new("You have already voted for this post") raise PostVote::Error.new("You have already voted for this post")
end end
end end

View File

@@ -60,16 +60,11 @@ class TagAlias < ActiveRecord::Base
include CacheMethods include CacheMethods
def self.to_aliased(names) def self.to_aliased(names)
alias_hash = Cache.get_multi(names.flatten, "ta") do |name| Array(names).flatten.map do |name|
ta = TagAlias.find_by_antecedent_name(name) Cache.get("ta:#{Cache.sanitize(name)}") do
if ta && ta.is_active? ActiveRecord::Base.select_value_sql("select consequent_name from tag_aliases where status = 'active' and antecedent_name = ?", name) || name
ta.consequent_name
else
name
end end
end end.uniq
alias_hash.values.flatten.uniq
end end
def process! def process!