This commit is contained in:
r888888888
2014-03-17 17:51:49 -07:00
parent 81fed535ee
commit a7e129c660
2 changed files with 10 additions and 16 deletions

View File

@@ -834,27 +834,20 @@ class Post < ActiveRecord::Base
# #
# After expunging a child: # After expunging a child:
# - Move favorites to parent. # - Move favorites to parent.
# - Does the parent have any active children? # - Does the parent have any children?
# - Yes: Done. # - Yes: Done.
# - No: Update parent's has_children flag to false. # - No: Update parent's has_children flag to false.
# #
# After expunging a parent: # After expunging a parent:
# - Move favorites to the first child. # - Move favorites to the first child.
# - Reparent all active children to the first active child. # - Reparent all children to the first child.
module ClassMethods module ClassMethods
def update_has_children_flag_for(post_id) def update_has_children_flag_for(post_id)
return if post_id.nil? return if post_id.nil?
has_children = Post.exists?(["is_deleted = ? AND parent_id = ?", false, post_id]) has_children = Post.where("parent_id = ?", post_id).exists?
execute_sql("UPDATE posts SET has_children = ? WHERE id = ?", has_children, post_id) execute_sql("UPDATE posts SET has_children = ? WHERE id = ?", has_children, post_id)
end end
def recalculate_has_children_for_all_posts
transaction do
execute_sql("UPDATE posts SET has_children = false WHERE has_children = true")
execute_sql("UPDATE posts SET has_children = true WHERE id IN (SELECT p.parent_id FROM posts p WHERE p.parent_id IS NOT NULL AND is_deleted = FALSE)")
end
end
end end
def self.included(m) def self.included(m)
@@ -882,9 +875,7 @@ class Post < ActiveRecord::Base
end end
def update_parent_on_destroy def update_parent_on_destroy
Post.update_has_children_flag_for(id)
Post.update_has_children_flag_for(parent_id) if parent_id Post.update_has_children_flag_for(parent_id) if parent_id
Post.update_has_children_flag_for(parent_id_was) if parent_id_was && parent_id != parent_id_was
end end
def update_children_on_destroy def update_children_on_destroy
@@ -894,8 +885,10 @@ class Post < ActiveRecord::Base
children.first.update_column(:parent_id, nil) children.first.update_column(:parent_id, nil)
else else
cached_children = children cached_children = children
cached_children[0].update_column(:parent_id, nil) eldest = cached_children[0]
Post.update_all({:parent_id => cached_children[0].id}, :id => cached_children[1..-1].map(&:id)) siblings = cached_children[1..-1]
eldest.update_column(:parent_id, nil)
Post.update_all({:parent_id => eldest.id}, :id => siblings.map(&:id))
end end
end end
@@ -942,10 +935,10 @@ class Post < ActiveRecord::Base
delete!(:without_mod_action => true) delete!(:without_mod_action => true)
give_favorites_to_parent give_favorites_to_parent
update_children_on_destroy update_children_on_destroy
update_parent_on_destroy
decrement_tag_post_counts decrement_tag_post_counts
remove_from_all_pools remove_from_all_pools
destroy destroy
update_parent_on_destroy
end end
def ban! def ban!
@@ -971,6 +964,7 @@ class Post < ActiveRecord::Base
update_column(:is_banned, true) if options[:ban] || has_tag?("banned_artist") update_column(:is_banned, true) if options[:ban] || has_tag?("banned_artist")
give_favorites_to_parent if options[:move_favorites] give_favorites_to_parent if options[:move_favorites]
unless options[:without_mod_action] unless options[:without_mod_action]
if options[:reason] if options[:reason]
ModAction.create(:description => "deleted post ##{id}, reason: #{options[:reason]}") ModAction.create(:description => "deleted post ##{id}, reason: #{options[:reason]}")

View File

@@ -2,7 +2,7 @@
app_path = "/var/www/danbooru2/current" app_path = "/var/www/danbooru2/current"
# Set unicorn options # Set unicorn options
worker_processes 10 worker_processes 22
preload_app false preload_app false
timeout 180 timeout 180