pools: stop using the pool_string field (#4160).
Stop using the pool_string field internally, but keep maintaining it until we can drop it later. * Stop using the pool_string for `pool:<name>` metatag searches. * Stop using the pool_string in the `Post#pools` method. This is used to get the list of pools on post show pages.
This commit is contained in:
@@ -211,10 +211,38 @@ class PostQueryBuilder
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if q[:pool] == "none"
|
q[:pool].to_a.each do |pool_name|
|
||||||
relation = relation.where("posts.pool_string = ''")
|
case pool_name
|
||||||
elsif q[:pool] == "any"
|
when "none"
|
||||||
relation = relation.where("posts.pool_string != ''")
|
relation = relation.where.not(id: Pool.select("unnest(post_ids)"))
|
||||||
|
when "any"
|
||||||
|
relation = relation.where(id: Pool.select("unnest(post_ids)"))
|
||||||
|
when "series"
|
||||||
|
relation = relation.where(id: Pool.series.select("unnest(post_ids)"))
|
||||||
|
when "collection"
|
||||||
|
relation = relation.where(id: Pool.collection.select("unnest(post_ids)"))
|
||||||
|
when /\*/
|
||||||
|
relation = relation.where(id: Pool.name_matches(pool_name).select("unnest(post_ids)"))
|
||||||
|
else
|
||||||
|
relation = relation.where(id: Pool.named(pool_name).select("unnest(post_ids)"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
q[:pool_neg].to_a.each do |pool_name|
|
||||||
|
case pool_name
|
||||||
|
when "none"
|
||||||
|
relation = relation.where(id: Pool.select("unnest(post_ids)"))
|
||||||
|
when "any"
|
||||||
|
relation = relation.where.not(id: Pool.select("unnest(post_ids)"))
|
||||||
|
when "series"
|
||||||
|
relation = relation.where.not(id: Pool.series.select("unnest(post_ids)"))
|
||||||
|
when "collection"
|
||||||
|
relation = relation.where.not(id: Pool.collection.select("unnest(post_ids)"))
|
||||||
|
when /\*/
|
||||||
|
relation = relation.where.not(id: Pool.name_matches(pool_name).select("unnest(post_ids)"))
|
||||||
|
else
|
||||||
|
relation = relation.where.not(id: Pool.named(pool_name).select("unnest(post_ids)"))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if q[:saved_searches]
|
if q[:saved_searches]
|
||||||
|
|||||||
@@ -112,16 +112,20 @@ class Pool < ApplicationRecord
|
|||||||
normalize_name(name).mb_chars.downcase
|
normalize_name(name).mb_chars.downcase
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_by_name(name)
|
def self.named(name)
|
||||||
if name =~ /^\d+$/
|
if name =~ /^\d+$/
|
||||||
where("pools.id = ?", name.to_i).first
|
where("pools.id = ?", name.to_i)
|
||||||
elsif name
|
elsif name
|
||||||
where_ilike(:name, normalize_name_for_search(name)).first
|
where_ilike(:name, normalize_name_for_search(name))
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.find_by_name(name)
|
||||||
|
named(name).try(:first)
|
||||||
|
end
|
||||||
|
|
||||||
def versions
|
def versions
|
||||||
if PoolArchive.enabled?
|
if PoolArchive.enabled?
|
||||||
PoolArchive.where("pool_id = ?", id).order("id asc")
|
PoolArchive.where("pool_id = ?", id).order("id asc")
|
||||||
|
|||||||
@@ -1020,11 +1020,7 @@ class Post < ApplicationRecord
|
|||||||
|
|
||||||
module PoolMethods
|
module PoolMethods
|
||||||
def pools
|
def pools
|
||||||
@pools ||= begin
|
Pool.where("pools.post_ids && array[?]", id).series_first
|
||||||
return Pool.none if pool_string.blank?
|
|
||||||
pool_ids = pool_string.scan(/\d+/)
|
|
||||||
Pool.where(id: pool_ids).series_first
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_active_pools?
|
def has_active_pools?
|
||||||
|
|||||||
@@ -619,37 +619,15 @@ class Tag < ApplicationRecord
|
|||||||
q[:disapproval_neg] << g2
|
q[:disapproval_neg] << g2
|
||||||
|
|
||||||
when "-pool"
|
when "-pool"
|
||||||
if g2.downcase == "none"
|
q[:pool_neg] ||= []
|
||||||
q[:pool] = "any"
|
q[:pool_neg] << g2
|
||||||
elsif g2.downcase == "any"
|
|
||||||
q[:pool] = "none"
|
|
||||||
elsif g2.downcase == "series"
|
|
||||||
q[:tags][:exclude] << "pool:series"
|
|
||||||
elsif g2.downcase == "collection"
|
|
||||||
q[:tags][:exclude] << "pool:collection"
|
|
||||||
else
|
|
||||||
q[:tags][:exclude] << "pool:#{Pool.name_to_id(g2)}"
|
|
||||||
end
|
|
||||||
|
|
||||||
when "pool"
|
when "pool"
|
||||||
if g2.downcase == "none"
|
q[:pool] ||= []
|
||||||
q[:pool] = "none"
|
q[:pool] << g2
|
||||||
elsif g2.downcase == "any"
|
|
||||||
q[:pool] = "any"
|
|
||||||
elsif g2.downcase == "series"
|
|
||||||
q[:tags][:related] << "pool:series"
|
|
||||||
elsif g2.downcase == "collection"
|
|
||||||
q[:tags][:related] << "pool:collection"
|
|
||||||
elsif g2.include?("*")
|
|
||||||
pool_ids = Pool.search(name_matches: g2, order: "post_count").limit(Danbooru.config.tag_query_limit).pluck(:id)
|
|
||||||
q[:tags][:include] += pool_ids.map { |id| "pool:#{id}" }
|
|
||||||
else
|
|
||||||
q[:tags][:related] << "pool:#{Pool.name_to_id(g2)}"
|
|
||||||
end
|
|
||||||
|
|
||||||
when "ordpool"
|
when "ordpool"
|
||||||
pool_id = Pool.name_to_id(g2)
|
pool_id = Pool.name_to_id(g2)
|
||||||
q[:tags][:related] << "pool:#{pool_id}"
|
|
||||||
q[:ordpool] = pool_id
|
q[:ordpool] = pool_id
|
||||||
|
|
||||||
when "-favgroup"
|
when "-favgroup"
|
||||||
|
|||||||
@@ -143,6 +143,16 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with pools" do
|
||||||
|
should "render the pool list" do
|
||||||
|
as(@user) { @post.update(tag_string: "newpool:comic") }
|
||||||
|
get post_path(@post)
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
assert_select "#pool-nav .pool-name", /Pool: comic/
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "with only deleted comments" do
|
context "with only deleted comments" do
|
||||||
setup do
|
setup do
|
||||||
as(@user) { create(:comment, post: @post, is_deleted: true) }
|
as(@user) { create(:comment, post: @post, is_deleted: true) }
|
||||||
|
|||||||
@@ -1948,17 +1948,28 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
should "return posts for the pool:<name> metatag" do
|
should "return posts for the pool:<name> metatag" do
|
||||||
SqsService.any_instance.stubs(:send_message)
|
SqsService.any_instance.stubs(:send_message)
|
||||||
|
|
||||||
FactoryBot.create(:pool, name: "test_a", category: "series")
|
pool1 = create(:pool, name: "test_a", category: "series")
|
||||||
FactoryBot.create(:pool, name: "test_b", category: "collection")
|
pool2 = create(:pool, name: "test_b", category: "collection")
|
||||||
post1 = FactoryBot.create(:post, tag_string: "pool:test_a")
|
post1 = create(:post, tag_string: "pool:test_a")
|
||||||
post2 = FactoryBot.create(:post, tag_string: "pool:test_b")
|
post2 = create(:post, tag_string: "pool:test_b")
|
||||||
|
|
||||||
|
assert_tag_match([post1], "pool:#{pool1.id}")
|
||||||
|
assert_tag_match([post2], "pool:#{pool2.id}")
|
||||||
|
|
||||||
|
assert_tag_match([post1], "pool:TEST_A")
|
||||||
|
assert_tag_match([post2], "pool:Test_B")
|
||||||
|
|
||||||
assert_tag_match([post1], "pool:test_a")
|
assert_tag_match([post1], "pool:test_a")
|
||||||
assert_tag_match([post2], "-pool:test_a")
|
assert_tag_match([post2], "-pool:test_a")
|
||||||
|
|
||||||
|
assert_tag_match([], "pool:test_a pool:test_b")
|
||||||
assert_tag_match([], "-pool:test_a -pool:test_b")
|
assert_tag_match([], "-pool:test_a -pool:test_b")
|
||||||
|
|
||||||
assert_tag_match([post2, post1], "pool:test*")
|
assert_tag_match([post2, post1], "pool:test*")
|
||||||
|
|
||||||
assert_tag_match([post2, post1], "pool:any")
|
assert_tag_match([post2, post1], "pool:any")
|
||||||
|
assert_tag_match([post2, post1], "-pool:none")
|
||||||
|
assert_tag_match([], "-pool:any")
|
||||||
assert_tag_match([], "pool:none")
|
assert_tag_match([], "pool:none")
|
||||||
|
|
||||||
assert_tag_match([post1], "pool:series")
|
assert_tag_match([post1], "pool:series")
|
||||||
|
|||||||
Reference in New Issue
Block a user