This commit is contained in:
Toks
2013-05-06 15:17:07 -04:00
6 changed files with 43 additions and 35 deletions

View File

@@ -7,6 +7,7 @@ class Note < ActiveRecord::Base
before_validation :initialize_updater
before_validation :blank_body
validates_presence_of :post_id, :creator_id, :updater_id, :x, :y, :width, :height
validate :coordinates_in_range, :message => "must be inside the image"
has_many :versions, :class_name => "NoteVersion", :order => "note_versions.id ASC"
after_save :update_post
after_save :create_version
@@ -95,6 +96,13 @@ class Note < ActiveRecord::Base
self.updater_ip_addr = CurrentUser.ip_addr
end
def coordinates_in_range
if x < 0 || y < 0 || (x > post.image_width) || (y > post.image_height)
self.errors.add(:coordinates, "must be inside the image")
return false
end
end
def post_must_not_be_note_locked
if is_locked?
errors.add :post, "is note locked"

View File

@@ -324,8 +324,6 @@ class Post < ActiveRecord::Base
def update_tag_post_counts
decrement_tags = tag_array_was - tag_array
increment_tags = tag_array - tag_array_was
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
@@ -338,7 +336,7 @@ class Post < ActiveRecord::Base
self.tag_count_copyright = 0
self.tag_count_character = 0
categories = Tag.categories_for(tag_array)
categories = Tag.categories_for(tag_array, :disable_caching => true)
categories.each_value do |category|
self.tag_count += 1

View File

@@ -66,20 +66,21 @@ class Tag < ActiveRecord::Base
select_value_sql("SELECT category FROM tags WHERE name = ?", tag_name).to_i
end
def category_for(tag_name)
Cache.get("tc:#{Cache.sanitize(tag_name)}") do
def category_for(tag_name, options = {})
if options[:disable_caching]
select_category_for(tag_name)
else
Cache.get("tc:#{Cache.sanitize(tag_name)}") do
select_category_for(tag_name)
end
end
end
def categories_for(tag_names)
def categories_for(tag_names, options)
Array(tag_names).inject({}) do |hash, tag_name|
hash[tag_name] = category_for(tag_name)
hash[tag_name] = category_for(tag_name, options)
hash
end
# Cache.get_multi(tag_names, "tc") do |name|
# select_category_for(name)
# end
end
end
@@ -104,11 +105,7 @@ class Tag < ActiveRecord::Base
Post.raw_tag_match(name).find_each do |post|
post.reload
post.set_tag_counts
post.update_column(:tag_count, post.tag_count)
post.update_column(:tag_count_general, post.tag_count_general)
post.update_column(:tag_count_artist, post.tag_count_artist)
post.update_column(:tag_count_copyright, post.tag_count_copyright)
post.update_column(:tag_count_character, post.tag_count_character)
Post.update_all({:tag_count => post.tag_count, :tag_count_general => post.tag_count_general, :tag_count_artist => post.tag_count_artist, :tag_count_copyright => post.tag_count_copyright, :tag_count_character => post.tag_count_character}, {:id => post.id})
end
end
end