[Cleanup] Remove pool is_deleted

Pools are hard-deleted now. There are also a few pools with this flag
which can't be properly deleted at the moment
This commit is contained in:
Earlopain 2022-07-11 22:52:26 +02:00
parent bdfea45e0e
commit 7e33ea8271
No known key found for this signature in database
GPG Key ID: 6CFB948E15246897
17 changed files with 23 additions and 94 deletions

View File

@ -5,7 +5,7 @@ class PoolElementsController < ApplicationController
def create
@pool = Pool.find_by_name(params[:pool_name]) || Pool.find_by_id(params[:pool_id])
if @pool.present? && !@pool.is_deleted?
if @pool.present?
@post = Post.find(params[:post_id])
@pool.with_lock do
@pool.add(@post.id)

View File

@ -10,9 +10,6 @@ class PoolsController < ApplicationController
def edit
@pool = Pool.find(params[:id])
if @pool.is_deleted && !@pool.deletable_by?(CurrentUser.user)
raise User::PrivilegeError
end
respond_with(@pool)
end

View File

@ -19,8 +19,6 @@ class ModActionDecorator < ApplicationDecorator
### Pools ###
when "pool_delete"
"Deleted pool ##{vals['pool_id']} (named #{vals['pool_name']}) by #{user}"
when "pool_undelete"
"Undeleted pool ##{vals['pool_id']} (named #{vals['pool_name']}) by #{user}"
### Takedowns ###
when "takedown_process"

View File

@ -40,7 +40,6 @@ class ModAction < ApplicationRecord
:ip_ban_create,
:ip_ban_delete,
:pool_delete,
:pool_undelete,
:report_reason_create,
:report_reason_delete,
:report_reason_update,

View File

@ -15,7 +15,6 @@ class Pool < ApplicationRecord
validates :category, inclusion: { :in => %w(series collection) }
validate :updater_can_change_category
validate :updater_can_remove_posts
validate :updater_can_edit_deleted
validate :validate_number_of_posts
before_validation :normalize_post_ids
before_validation :normalize_name
@ -35,14 +34,6 @@ class Pool < ApplicationRecord
where("pools.creator_id = ?", id)
end
def deleted
where("pools.is_deleted = true")
end
def undeleted
where("pools.is_deleted = false")
end
def series
where("pools.category = ?", "series")
end
@ -95,7 +86,6 @@ class Pool < ApplicationRecord
end
q = q.attribute_matches(:is_active, params[:is_active])
q = q.attribute_matches(:is_deleted, params[:is_deleted])
case params[:order]
when "name"
@ -218,20 +208,10 @@ class Pool < ApplicationRecord
user.is_janitor?
end
def updater_can_edit_deleted
if is_deleted? && !deletable_by?(CurrentUser.user)
errors.add(:base, "You cannot update pools that are deleted")
end
end
def create_mod_action_for_delete
ModAction.log(:pool_delete, {pool_id: id, pool_name: name, user_id: creator_id})
end
def create_mod_action_for_undelete
ModAction.log(:pool_undelete, {pool_id: id, pool_name: name, user_id: creator_id})
end
def validate_number_of_posts
post_ids_before = post_ids_before_last_save || post_ids_was
added = post_ids - post_ids_before
@ -248,14 +228,13 @@ class Pool < ApplicationRecord
return if post.nil?
return if post.id.nil?
return if contains?(post.id)
return if is_deleted?
with_lock do
reload
self.skip_sync = true
update(post_ids: post_ids + [post.id])
self.skip_sync = false
post.add_pool!(self, true)
post.add_pool!(self)
post.save
end
end
@ -263,7 +242,6 @@ class Pool < ApplicationRecord
def add(id)
return if id.nil?
return if contains?(id)
return if is_deleted?
self.post_ids << id
end
@ -303,7 +281,7 @@ class Pool < ApplicationRecord
removed = post_ids_before - post_ids
Post.where(id: added).find_each do |post|
post.add_pool!(self, true)
post.add_pool!(self)
post.save
end

View File

@ -49,7 +49,6 @@ class PoolArchive < ApplicationRecord
description: pool.description,
name: pool.name,
is_active: pool.is_active?,
is_deleted: pool.is_deleted?,
category: pool.category
})
end

View File

@ -971,16 +971,15 @@ class Post < ApplicationRecord
end
def has_active_pools?
pools.undeleted.length > 0
pools.any?
end
def belongs_to_pool?(pool)
pool_string =~ /(?:\A| )pool:#{pool.id}(?:\Z| )/
end
def add_pool!(pool, force = false)
def add_pool!(pool)
return if belongs_to_pool?(pool)
return if pool.is_deleted? && !force
with_lock do
self.pool_string = "#{pool_string} pool:#{pool.id}".strip
@ -1519,12 +1518,12 @@ class Post < ApplicationRecord
end
def with_pool_stats
pool_posts = Pool.joins("CROSS JOIN unnest(post_ids) AS post_id").select(:id, :is_deleted, :category, "post_id")
pool_posts = Pool.joins("CROSS JOIN unnest(post_ids) AS post_id").select(:id, :category, "post_id")
relation = joins("LEFT OUTER JOIN (#{pool_posts.to_sql}) pools ON pools.post_id = posts.id").group(:id).select("posts.*")
relation = relation.select("COUNT(pools.id) AS pool_count")
relation = relation.select("COUNT(pools.id) FILTER (WHERE pools.is_deleted = TRUE) AS deleted_pool_count")
relation = relation.select("COUNT(pools.id) FILTER (WHERE pools.is_deleted = FALSE) AS active_pool_count")
relation = relation.select("0 AS deleted_pool_count")
relation = relation.select("COUNT(pools.id) AS active_pool_count")
relation = relation.select("COUNT(pools.id) FILTER (WHERE pools.category = 'series') AS series_pool_count")
relation = relation.select("COUNT(pools.id) FILTER (WHERE pools.category = 'collection') AS collection_pool_count")
relation

View File

@ -262,7 +262,7 @@ class PostPresenter < Presenter
end
def has_nav_links?(template)
has_sequential_navigation?(template.params) || @post.pools.undeleted.any? || @post.post_sets.visible.any?
has_sequential_navigation?(template.params) || @post.has_active_pools? || @post.post_sets.visible.any?
end
def has_sequential_navigation?(params)

View File

@ -26,7 +26,7 @@
</li>
<li><strong>Source</strong>: <%= post.source %></li>
<% if post.has_active_pools? %>
<li><strong>Pools</strong>: <%= render "pools/inline_list", pools: post.pools.undeleted %></li>
<li><strong>Pools</strong>: <%= render "pools/inline_list", pools: post.pools %></li>
<% end %>
<li><strong>Tags</strong>: <%= post.presenter.inline_tag_list_html %></li>
</ul>

View File

@ -14,11 +14,7 @@
<%= subnav_link_to "Import", import_pool_path(@pool), "data-shortcut": "i" %>
<% end %>
<% if @pool.deletable_by?(CurrentUser.user) %>
<% if @pool.is_deleted? %>
<%= subnav_link_to "Undelete", undelete_pool_path(@pool), :method => :post %>
<% else %>
<%= subnav_link_to "Delete", pool_path(@pool), :method => :delete, :"data-shortcut" => "shift+d", :"data-confirm" => "Are you sure you want to delete this pool?" %>
<% end %>
<%= subnav_link_to "Delete", pool_path(@pool), :method => :delete, :"data-shortcut" => "shift+d", :"data-confirm" => "Are you sure you want to delete this pool?" %>
<% end %>
<%= subnav_link_to "History", pool_versions_path(:search => {:pool_id => @pool.id}) %>
<% if @pool.post_count <= 1_000 && CurrentUser.is_member? %>

View File

@ -18,9 +18,6 @@
</td>
<td>
<%= link_to pool.pretty_name, pool_path(pool) %>
<% if pool.is_deleted? %>
<span class="inactive">(deleted)</span>
<% end %>
<% if pool.post_count > CurrentUser.user.per_page %>
<%= link_to "page #{pool.last_page}", pool_path(pool, :page => pool.last_page), :class => "last-page" %>

View File

@ -3,9 +3,6 @@
<h2>
<%= @pool.pretty_category %>:
<%= link_to @pool.pretty_name, posts_path(:tags => "pool:#{@pool.id}"), :class => "pool-category-#{@pool.category}" %>
<% if @pool.is_deleted? %>
<span class="inactive">(deleted)</span>
<% end %>
</h2>
<div id="description" class="dtext-container">

View File

@ -3,8 +3,8 @@
<%= render "posts/partials/show/search_seq", :post => post %>
<% end %>
<% if post.pools.undeleted.any? %>
<%= render "posts/partials/show/pool_list", post: post, pools: post.pools.undeleted.selected_first(params[:pool_id]).limit(5) %>
<% if post.has_active_pools? %>
<%= render "posts/partials/show/pool_list", post: post, pools: post.pools.selected_first(params[:pool_id]).limit(5) %>
<% end %>
<% if CurrentUser.is_member? && post.post_sets.owned.any? %>

View File

@ -0,0 +1,6 @@
class RemovePoolIsDeleted < ActiveRecord::Migration[6.1]
def up
remove_column :pools, :is_deleted
remove_column :pool_versions, :is_deleted
end
end

View File

@ -1209,7 +1209,6 @@ CREATE TABLE public.pool_versions (
created_at timestamp without time zone,
updated_at timestamp without time zone,
is_active boolean DEFAULT true NOT NULL,
is_deleted boolean DEFAULT false NOT NULL,
category character varying,
version integer DEFAULT 1 NOT NULL
);
@ -1245,7 +1244,6 @@ CREATE TABLE public.pools (
description text,
is_active boolean DEFAULT true NOT NULL,
post_ids integer[] DEFAULT '{}'::integer[] NOT NULL,
is_deleted boolean DEFAULT false NOT NULL,
created_at timestamp without time zone,
updated_at timestamp without time zone,
category character varying DEFAULT 'series'::character varying NOT NULL
@ -4747,4 +4745,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20220203154846'),
('20220219202441'),
('20220316162257'),
('20220516103329');
('20220516103329'),
('20220710133556');

View File

@ -171,32 +171,6 @@ class PoolTest < ActiveSupport::TestCase
assert_equal(1, @pool.post_count)
end
end
context "to a deleted pool" do
setup do
# must be a janitor to update deleted pools.
CurrentUser.user = FactoryBot.create(:janitor_user)
@pool.update_attribute(:is_deleted, true)
@pool.post_ids += [@p2.id]
@pool.synchronize!
@pool.save
@pool.reload
@p2.reload
end
should "add the post to the pool" do
assert_equal([@p1.id, @p2.id], @pool.post_ids)
end
should "add the pool to the post" do
assert_equal("pool:#{@pool.id}", @p2.pool_string)
end
should "increment the post count" do
assert_equal(2, @pool.post_count)
end
end
end
context "by removing a post" do

View File

@ -93,29 +93,17 @@ class PostTest < ActiveSupport::TestCase
context "that belongs to a pool" do
setup do
# must be a janitor to update deleted pools. must be >1 week old to remove posts from pools.
CurrentUser.user = FactoryBot.create(:janitor_user, created_at: 1.month.ago)
@pool = FactoryBot.create(:pool)
@pool.add!(@post)
@deleted_pool = FactoryBot.create(:pool)
@deleted_pool.add!(@post)
@deleted_pool.update_columns(is_deleted: true)
@post.expunge!
@pool.reload
@deleted_pool.reload
end
should "remove the post from all pools" do
assert_equal([], @pool.post_ids)
end
should "remove the post from deleted pools" do
assert_equal([], @deleted_pool.post_ids)
end
should "destroy the record" do
assert_equal([], @post.errors.full_messages)
assert_equal(0, Post.where("id = ?", @post.id).count)