pools: drop post_count column (fix #3667)
This commit is contained in:
@@ -84,7 +84,7 @@ class Pool < ApplicationRecord
|
|||||||
when "created_at"
|
when "created_at"
|
||||||
q = q.order("pools.created_at desc")
|
q = q.order("pools.created_at desc")
|
||||||
when "post_count"
|
when "post_count"
|
||||||
q = q.order("pools.post_count desc").default_order
|
q = q.order(Arel.sql("cardinality(post_ids) desc")).default_order
|
||||||
else
|
else
|
||||||
q = q.apply_default_order(params)
|
q = q.apply_default_order(params)
|
||||||
end
|
end
|
||||||
@@ -207,7 +207,7 @@ class Pool < ApplicationRecord
|
|||||||
return if is_deleted?
|
return if is_deleted?
|
||||||
|
|
||||||
with_lock do
|
with_lock do
|
||||||
update(post_ids: post_ids + [post.id], post_count: post_count + 1)
|
update(post_ids: post_ids + [post.id])
|
||||||
post.add_pool!(self, true)
|
post.add_pool!(self, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -218,7 +218,7 @@ class Pool < ApplicationRecord
|
|||||||
|
|
||||||
with_lock do
|
with_lock do
|
||||||
reload
|
reload
|
||||||
update(post_ids: post_ids - [post.id], post_count: post_count - 1)
|
update(post_ids: post_ids - [post.id])
|
||||||
post.remove_pool!(self)
|
post.remove_pool!(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -255,7 +255,6 @@ class Pool < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
normalize_post_ids
|
normalize_post_ids
|
||||||
self.post_count = post_ids.size
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def synchronize!
|
def synchronize!
|
||||||
@@ -263,6 +262,10 @@ class Pool < ApplicationRecord
|
|||||||
save if will_save_change_to_post_ids?
|
save if will_save_change_to_post_ids?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def post_count
|
||||||
|
post_ids.size
|
||||||
|
end
|
||||||
|
|
||||||
def first_post?(post_id)
|
def first_post?(post_id)
|
||||||
page_number(post_id) == 1
|
page_number(post_id) == 1
|
||||||
end
|
end
|
||||||
@@ -297,7 +300,7 @@ class Pool < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def method_attributes
|
def method_attributes
|
||||||
super + [:creator_name]
|
super + [:creator_name, :post_count]
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_category_pseudo_tags_for_posts_async
|
def update_category_pseudo_tags_for_posts_async
|
||||||
|
|||||||
10
db/migrate/20181108205842_drop_post_count_from_pools.rb
Normal file
10
db/migrate/20181108205842_drop_post_count_from_pools.rb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
class DropPostCountFromPools < ActiveRecord::Migration[5.2]
|
||||||
|
def up
|
||||||
|
remove_column :pools, :post_count
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
add_column :pools, :post_count, :integer, default: 0, null: false
|
||||||
|
Pool.update_all("post_count = cardinality(post_ids)")
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -2564,7 +2564,6 @@ CREATE TABLE public.pools (
|
|||||||
description text,
|
description text,
|
||||||
is_active boolean DEFAULT true NOT NULL,
|
is_active boolean DEFAULT true NOT NULL,
|
||||||
post_ids integer[] DEFAULT '{}'::integer[] NOT NULL,
|
post_ids integer[] DEFAULT '{}'::integer[] NOT NULL,
|
||||||
post_count integer DEFAULT 0 NOT NULL,
|
|
||||||
is_deleted boolean DEFAULT false NOT NULL,
|
is_deleted boolean DEFAULT false NOT NULL,
|
||||||
created_at timestamp without time zone,
|
created_at timestamp without time zone,
|
||||||
updated_at timestamp without time zone,
|
updated_at timestamp without time zone,
|
||||||
@@ -7579,6 +7578,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
|||||||
('20180912185624'),
|
('20180912185624'),
|
||||||
('20180913184128'),
|
('20180913184128'),
|
||||||
('20180916002448'),
|
('20180916002448'),
|
||||||
('20181108162204');
|
('20181108162204'),
|
||||||
|
('20181108205842');
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user