From a7e129c6603c65dbdc106323c5fb59b9ec0cce6c Mon Sep 17 00:00:00 2001 From: r888888888 Date: Mon, 17 Mar 2014 17:51:49 -0700 Subject: [PATCH] fixes #1513 --- app/models/post.rb | 24 +++++++++--------------- config/unicorn/production.rb | 2 +- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index c610e7a3b..60ec27de4 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -834,27 +834,20 @@ class Post < ActiveRecord::Base # # After expunging a child: # - Move favorites to parent. - # - Does the parent have any active children? + # - Does the parent have any children? # - Yes: Done. # - No: Update parent's has_children flag to false. # # After expunging a parent: # - Move favorites to the first child. - # - Reparent all active children to the first active child. + # - Reparent all children to the first child. module ClassMethods def update_has_children_flag_for(post_id) 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) 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 def self.included(m) @@ -882,9 +875,7 @@ class Post < ActiveRecord::Base end 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_was) if parent_id_was && parent_id != parent_id_was end def update_children_on_destroy @@ -894,8 +885,10 @@ class Post < ActiveRecord::Base children.first.update_column(:parent_id, nil) else cached_children = children - cached_children[0].update_column(:parent_id, nil) - Post.update_all({:parent_id => cached_children[0].id}, :id => cached_children[1..-1].map(&:id)) + eldest = cached_children[0] + siblings = cached_children[1..-1] + eldest.update_column(:parent_id, nil) + Post.update_all({:parent_id => eldest.id}, :id => siblings.map(&:id)) end end @@ -942,10 +935,10 @@ class Post < ActiveRecord::Base delete!(:without_mod_action => true) give_favorites_to_parent update_children_on_destroy - update_parent_on_destroy decrement_tag_post_counts remove_from_all_pools destroy + update_parent_on_destroy end def ban! @@ -971,6 +964,7 @@ class Post < ActiveRecord::Base update_column(:is_banned, true) if options[:ban] || has_tag?("banned_artist") give_favorites_to_parent if options[:move_favorites] + unless options[:without_mod_action] if options[:reason] ModAction.create(:description => "deleted post ##{id}, reason: #{options[:reason]}") diff --git a/config/unicorn/production.rb b/config/unicorn/production.rb index f364c975f..8cd19f678 100644 --- a/config/unicorn/production.rb +++ b/config/unicorn/production.rb @@ -2,7 +2,7 @@ app_path = "/var/www/danbooru2/current" # Set unicorn options -worker_processes 10 +worker_processes 22 preload_app false timeout 180