Post#tag_match: clean up read_only param.
* Drop /posts?ro=true param (broken). * Clean up tag_match (rescuing PG::ConnectionBad didn't do anything, we just build the query here, we don't run it).
This commit is contained in:
@@ -9,7 +9,7 @@ class PostsController < ApplicationController
|
|||||||
format.html { redirect_to(@post) }
|
format.html { redirect_to(@post) }
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@post_set = PostSets::Post.new(tag_query, params[:page], params[:limit], raw: params[:raw], random: params[:random], format: params[:format], read_only: params[:ro])
|
@post_set = PostSets::Post.new(tag_query, params[:page], params[:limit], raw: params[:raw], random: params[:random], format: params[:format])
|
||||||
@posts = @post_set.posts
|
@posts = @post_set.posts
|
||||||
respond_with(@posts) do |format|
|
respond_with(@posts) do |format|
|
||||||
format.atom
|
format.atom
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
module PostSets
|
module PostSets
|
||||||
class Post < PostSets::Base
|
class Post < PostSets::Base
|
||||||
MAX_PER_PAGE = 200
|
MAX_PER_PAGE = 200
|
||||||
attr_reader :tag_array, :page, :raw, :random, :post_count, :format, :read_only
|
attr_reader :tag_array, :page, :raw, :random, :post_count, :format
|
||||||
|
|
||||||
def initialize(tags, page = 1, per_page = nil, options = {})
|
def initialize(tags, page = 1, per_page = nil, options = {})
|
||||||
@tag_array = Tag.scan_query(tags)
|
@tag_array = Tag.scan_query(tags)
|
||||||
@@ -10,7 +10,6 @@ module PostSets
|
|||||||
@raw = options[:raw].present?
|
@raw = options[:raw].present?
|
||||||
@random = options[:random].present?
|
@random = options[:random].present?
|
||||||
@format = options[:format] || "html"
|
@format = options[:format] || "html"
|
||||||
@read_only = options[:read_only]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_string
|
def tag_string
|
||||||
@@ -134,7 +133,7 @@ module PostSets
|
|||||||
elsif raw
|
elsif raw
|
||||||
temp = ::Post.raw_tag_match(tag_string).order("posts.id DESC").where("true /* PostSets::Post#posts:1 */").paginate(page, :count => post_count, :limit => per_page)
|
temp = ::Post.raw_tag_match(tag_string).order("posts.id DESC").where("true /* PostSets::Post#posts:1 */").paginate(page, :count => post_count, :limit => per_page)
|
||||||
else
|
else
|
||||||
temp = ::Post.tag_match(tag_string, read_only).where("true /* PostSets::Post#posts:2 */").paginate(page, :count => post_count, :limit => per_page)
|
temp = ::Post.tag_match(tag_string).where("true /* PostSets::Post#posts:2 */").paginate(page, :count => post_count, :limit => per_page)
|
||||||
end
|
end
|
||||||
temp.each # hack to force rails to eager load
|
temp.each # hack to force rails to eager load
|
||||||
temp
|
temp
|
||||||
|
|||||||
@@ -1682,21 +1682,8 @@ class Post < ApplicationRecord
|
|||||||
where("posts.tag_index @@ to_tsquery('danbooru', E?)", tag.to_escaped_for_tsquery)
|
where("posts.tag_index @@ to_tsquery('danbooru', E?)", tag.to_escaped_for_tsquery)
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_match(query, read_only = false)
|
def tag_match(query, read_only: false)
|
||||||
if query =~ /status:deleted.status:deleted/
|
PostQueryBuilder.new(query, read_only: read_only).build
|
||||||
# temp fix for degenerate crawlers
|
|
||||||
raise ActiveRecord::RecordNotFound
|
|
||||||
end
|
|
||||||
|
|
||||||
if read_only
|
|
||||||
begin
|
|
||||||
PostQueryBuilder.new(query, read_only: true).build
|
|
||||||
rescue PG::ConnectionBad
|
|
||||||
PostQueryBuilder.new(query).build
|
|
||||||
end
|
|
||||||
else
|
|
||||||
PostQueryBuilder.new(query).build
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ class SavedSearch < ApplicationRecord
|
|||||||
CurrentUser.as_system do
|
CurrentUser.as_system do
|
||||||
redis_key = "search:#{query}"
|
redis_key = "search:#{query}"
|
||||||
return if redis.exists(redis_key)
|
return if redis.exists(redis_key)
|
||||||
post_ids = Post.tag_match(query, true).limit(QUERY_LIMIT).pluck(:id)
|
post_ids = Post.tag_match(query, read_only: true).limit(QUERY_LIMIT).pluck(:id)
|
||||||
redis.sadd(redis_key, post_ids)
|
redis.sadd(redis_key, post_ids)
|
||||||
redis.expire(redis_key, REDIS_EXPIRY)
|
redis.expire(redis_key, REDIS_EXPIRY)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user