pools: stop maintaining pool category pseudotags in pool strings (#4160)

Stop maintaining pool category pseudo tags (pool:series, pool:collection)
in pool strings. They're no longer used and the changes to the
`Post#pools` method in dc4d2e54b caused issues with this.

Also allow Members to change the category of large pools again. This was
only restricted because maintaining these pseudotags forced us to update
every post in the pool whenever a pool's category was changed.
This commit is contained in:
evazion
2019-09-08 23:28:02 -05:00
parent d0f060d8eb
commit 763ac1a7e0
7 changed files with 13 additions and 98 deletions

View File

@@ -1,8 +0,0 @@
class UpdatePoolPseudoTagsJob < ApplicationJob
queue_as :default
queue_with_priority 20
def perform(pool)
pool.update_category_pseudo_tags_for_posts
end
end

View File

@@ -8,12 +8,10 @@ class Pool < ApplicationRecord
validates_uniqueness_of :name, case_sensitive: false, if: :name_changed?
validate :validate_name, if: :name_changed?
validates_inclusion_of :category, :in => %w(series collection)
validate :updater_can_change_category
validate :updater_can_remove_posts
validate :updater_can_edit_deleted
before_validation :normalize_post_ids
before_validation :normalize_name
after_save :update_category_pseudo_tags_for_posts_async
after_save :create_version
after_create :synchronize!
@@ -294,30 +292,6 @@ class Pool < ApplicationRecord
creator.name
end
def update_category_pseudo_tags_for_posts_async
if saved_change_to_category?
UpdatePoolPseudoTagsJob.perform_later(self)
end
end
def update_category_pseudo_tags_for_posts
Post.where(id: post_ids).find_each do |post|
post.reload
post.set_pool_category_pseudo_tags
Post.where(:id => post.id).update_all(:pool_string => post.pool_string)
end
end
def category_changeable_by?(user)
user.is_builder? || (user.is_member? && post_count <= Danbooru.config.pool_category_change_limit)
end
def updater_can_change_category
if category_changed? && !category_changeable_by?(CurrentUser.user)
errors[:base] << "You cannot change the category of pools with greater than #{Danbooru.config.pool_category_change_limit} posts"
end
end
def validate_name
case name
when /\A(any|none|series|collection)\z/i

View File

@@ -30,7 +30,6 @@ class Post < ApplicationRecord
validate :updater_can_change_rating
before_save :update_tag_post_counts
before_save :set_tag_counts
after_save :set_pool_category_pseudo_tags
before_create :autoban
after_save :create_version
after_save :update_parent_on_save
@@ -1041,7 +1040,6 @@ class Post < ApplicationRecord
with_lock do
self.pool_string = "#{pool_string} pool:#{pool.id}".strip
set_pool_category_pseudo_tags
update_column(:pool_string, pool_string) unless new_record?
pool.add!(self)
end
@@ -1053,7 +1051,6 @@ class Post < ApplicationRecord
with_lock do
self.pool_string = pool_string.gsub(/(?:\A| )pool:#{pool.id}(?:\Z| )/, " ").strip
set_pool_category_pseudo_tags
update_column(:pool_string, pool_string) unless new_record?
pool.remove!(self)
end
@@ -1064,18 +1061,6 @@ class Post < ApplicationRecord
pool.remove!(self)
end
end
def set_pool_category_pseudo_tags
self.pool_string = (pool_string.split - ["pool:series", "pool:collection"]).join(" ")
pool_categories = pools.undeleted.pluck(:category)
if pool_categories.include?("series")
self.pool_string = "#{pool_string} pool:series".strip
end
if pool_categories.include?("collection")
self.pool_string = "#{pool_string} pool:collection".strip
end
end
end
module VoteMethods