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) }
|
||||
end
|
||||
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
|
||||
respond_with(@posts) do |format|
|
||||
format.atom
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module PostSets
|
||||
class Post < PostSets::Base
|
||||
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 = {})
|
||||
@tag_array = Tag.scan_query(tags)
|
||||
@@ -10,7 +10,6 @@ module PostSets
|
||||
@raw = options[:raw].present?
|
||||
@random = options[:random].present?
|
||||
@format = options[:format] || "html"
|
||||
@read_only = options[:read_only]
|
||||
end
|
||||
|
||||
def tag_string
|
||||
@@ -134,7 +133,7 @@ module PostSets
|
||||
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)
|
||||
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
|
||||
temp.each # hack to force rails to eager load
|
||||
temp
|
||||
|
||||
@@ -1682,21 +1682,8 @@ class Post < ApplicationRecord
|
||||
where("posts.tag_index @@ to_tsquery('danbooru', E?)", tag.to_escaped_for_tsquery)
|
||||
end
|
||||
|
||||
def tag_match(query, read_only = false)
|
||||
if query =~ /status:deleted.status:deleted/
|
||||
# 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
|
||||
def tag_match(query, read_only: false)
|
||||
PostQueryBuilder.new(query, read_only: read_only).build
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ class SavedSearch < ApplicationRecord
|
||||
CurrentUser.as_system do
|
||||
redis_key = "search:#{query}"
|
||||
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.expire(redis_key, REDIS_EXPIRY)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user