Fix various rubocop warnings.
This commit is contained in:
@@ -23,8 +23,7 @@ class ApiKey < ApplicationRecord
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :key, :user)
|
||||
q = q.apply_default_order(params)
|
||||
q
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
concerning :PermissionMethods do
|
||||
@@ -59,9 +58,11 @@ class ApiKey < ApplicationRecord
|
||||
end
|
||||
|
||||
def permissions_list
|
||||
Rails.application.routes.routes.select do |route|
|
||||
routes = Rails.application.routes.routes.select do |route|
|
||||
route.defaults[:controller].present? && !route.internal
|
||||
end.map do |route|
|
||||
end
|
||||
|
||||
routes.map do |route|
|
||||
"#{route.defaults[:controller]}:#{route.defaults[:action]}"
|
||||
end.uniq.sort
|
||||
end
|
||||
|
||||
@@ -26,7 +26,7 @@ class ApplicationRecord < ActiveRecord::Base
|
||||
|
||||
concerning :PrivilegeMethods do
|
||||
class_methods do
|
||||
def visible(user)
|
||||
def visible(_user)
|
||||
all
|
||||
end
|
||||
|
||||
@@ -47,14 +47,14 @@ class ApplicationRecord < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def multiple_includes
|
||||
reflections.reject { |k,v| v.macro != :has_many }.keys.map(&:to_sym)
|
||||
reflections.select { |_, v| v.macro == :has_many }.keys.map(&:to_sym)
|
||||
end
|
||||
|
||||
def associated_models(name)
|
||||
if reflections[name].options[:polymorphic]
|
||||
associated_models = reflections[name].active_record.try(:model_types) || []
|
||||
reflections[name].active_record.try(:model_types) || []
|
||||
else
|
||||
associated_models = [reflections[name].class_name]
|
||||
[reflections[name].class_name]
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -77,7 +77,7 @@ class ApplicationRecord < ActiveRecord::Base
|
||||
|
||||
def serializable_hash(options = {})
|
||||
options ||= {}
|
||||
if options[:only] && options[:only].is_a?(String)
|
||||
if options[:only].is_a?(String)
|
||||
options.delete(:methods)
|
||||
options.delete(:include)
|
||||
options.merge!(ParameterBuilder.serial_parameters(options[:only], self))
|
||||
@@ -116,20 +116,20 @@ class ApplicationRecord < ActiveRecord::Base
|
||||
concerning :ActiveRecordExtensions do
|
||||
class_methods do
|
||||
def without_timeout
|
||||
connection.execute("SET STATEMENT_TIMEOUT = 0") unless Rails.env == "test"
|
||||
connection.execute("SET STATEMENT_TIMEOUT = 0") unless Rails.env.test?
|
||||
yield
|
||||
ensure
|
||||
connection.execute("SET STATEMENT_TIMEOUT = #{CurrentUser.user.try(:statement_timeout) || 3_000}") unless Rails.env == "test"
|
||||
connection.execute("SET STATEMENT_TIMEOUT = #{CurrentUser.user.try(:statement_timeout) || 3_000}") unless Rails.env.test?
|
||||
end
|
||||
|
||||
def with_timeout(n, default_value = nil, new_relic_params = {})
|
||||
connection.execute("SET STATEMENT_TIMEOUT = #{n}") unless Rails.env == "test"
|
||||
connection.execute("SET STATEMENT_TIMEOUT = #{n}") unless Rails.env.test?
|
||||
yield
|
||||
rescue ::ActiveRecord::StatementInvalid => x
|
||||
DanbooruLogger.log(x, expected: false, **new_relic_params)
|
||||
return default_value
|
||||
rescue ::ActiveRecord::StatementInvalid => e
|
||||
DanbooruLogger.log(e, expected: false, **new_relic_params)
|
||||
default_value
|
||||
ensure
|
||||
connection.execute("SET STATEMENT_TIMEOUT = #{CurrentUser.user.try(:statement_timeout) || 3_000}") unless Rails.env == "test"
|
||||
connection.execute("SET STATEMENT_TIMEOUT = #{CurrentUser.user.try(:statement_timeout) || 3_000}") unless Rails.env.test?
|
||||
end
|
||||
|
||||
def update!(*args)
|
||||
@@ -161,7 +161,7 @@ class ApplicationRecord < ActiveRecord::Base
|
||||
end
|
||||
|
||||
concerning :DtextMethods do
|
||||
def dtext_shortlink(**options)
|
||||
def dtext_shortlink(**_options)
|
||||
"#{self.class.name.underscore.tr("_", " ")} ##{id}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -61,7 +61,7 @@ class Artist < ApplicationRecord
|
||||
concerning :NameMethods do
|
||||
class_methods do
|
||||
def normalize_name(name)
|
||||
name.to_s.mb_chars.downcase.strip.gsub(/ /, '_').to_s
|
||||
name.to_s.mb_chars.downcase.strip.gsub(/ /, "_").to_s
|
||||
end
|
||||
|
||||
def normalize_other_names(other_names)
|
||||
@@ -216,7 +216,7 @@ class Artist < ApplicationRecord
|
||||
end
|
||||
|
||||
def any_name_matches(query)
|
||||
if query =~ %r!\A/(.*)/\z!
|
||||
if query =~ %r{\A/(.*)/\z}
|
||||
where_regex(:name, $1).or(any_other_name_matches($1)).or(where_regex(:group_name, $1))
|
||||
else
|
||||
normalized_name = normalize_name(query)
|
||||
@@ -228,11 +228,11 @@ class Artist < ApplicationRecord
|
||||
def url_matches(query)
|
||||
query = query.strip
|
||||
|
||||
if query =~ %r!\A/(.*)/\z!
|
||||
if query =~ %r{\A/(.*)/\z}
|
||||
where(id: ArtistUrl.where_regex(:url, $1).select(:artist_id))
|
||||
elsif query.include?("*")
|
||||
where(id: ArtistUrl.where_like(:url, query).select(:artist_id))
|
||||
elsif query =~ %r!\Ahttps?://!i
|
||||
elsif query =~ %r{\Ahttps?://}i
|
||||
ArtistFinder.find_artists(query)
|
||||
else
|
||||
where(id: ArtistUrl.where_like(:url, "*#{query}*").select(:artist_id))
|
||||
@@ -242,7 +242,7 @@ class Artist < ApplicationRecord
|
||||
def any_name_or_url_matches(query)
|
||||
query = query.strip
|
||||
|
||||
if query =~ %r!\Ahttps?://!i
|
||||
if query =~ %r{\Ahttps?://}i
|
||||
url_matches(query)
|
||||
else
|
||||
any_name_matches(query)
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
class ArtistCommentary < ApplicationRecord
|
||||
class RevertError < StandardError; end
|
||||
|
||||
attr_accessor :remove_commentary_tag, :remove_commentary_request_tag, :remove_commentary_check_tag, :remove_partial_commentary_tag
|
||||
attr_accessor :add_commentary_tag, :add_commentary_request_tag, :add_commentary_check_tag, :add_partial_commentary_tag
|
||||
attr_accessor(
|
||||
:remove_commentary_tag, :remove_commentary_request_tag,
|
||||
:remove_commentary_check_tag, :remove_partial_commentary_tag,
|
||||
:add_commentary_tag, :add_commentary_request_tag, :add_commentary_check_tag,
|
||||
:add_partial_commentary_tag
|
||||
)
|
||||
|
||||
before_validation :trim_whitespace
|
||||
validates_uniqueness_of :post_id
|
||||
validates :post_id, uniqueness: true
|
||||
belongs_to :post
|
||||
has_many :versions, -> {order("artist_commentary_versions.id ASC")}, :class_name => "ArtistCommentaryVersion", :dependent => :destroy, :foreign_key => :post_id, :primary_key => :post_id
|
||||
has_one :previous_version, -> {order(id: :desc)}, :class_name => "ArtistCommentaryVersion", :foreign_key => :post_id, :primary_key => :post_id
|
||||
@@ -126,7 +131,7 @@ class ArtistCommentary < ApplicationRecord
|
||||
|
||||
def revert_to(version)
|
||||
if post_id != version.post_id
|
||||
raise RevertError.new("You cannot revert to a previous artist commentary of another post.")
|
||||
raise RevertError, "You cannot revert to a previous artist commentary of another post."
|
||||
end
|
||||
|
||||
self.original_description = version.original_description
|
||||
|
||||
@@ -22,23 +22,17 @@ class ArtistCommentaryVersion < ApplicationRecord
|
||||
end
|
||||
|
||||
def previous
|
||||
@previous ||= begin
|
||||
ArtistCommentaryVersion.where("post_id = ? and updated_at < ?", post_id, updated_at).order("updated_at desc").limit(1).to_a
|
||||
end
|
||||
@previous ||= ArtistCommentaryVersion.where("post_id = ? and updated_at < ?", post_id, updated_at).order("updated_at desc").limit(1).to_a
|
||||
@previous.first
|
||||
end
|
||||
|
||||
def subsequent
|
||||
@subsequent ||= begin
|
||||
ArtistCommentaryVersion.where("post_id = ? and updated_at > ?", post_id, updated_at).order("updated_at asc").limit(1).to_a
|
||||
end
|
||||
@subsequent ||= ArtistCommentaryVersion.where("post_id = ? and updated_at > ?", post_id, updated_at).order("updated_at asc").limit(1).to_a
|
||||
@subsequent.first
|
||||
end
|
||||
|
||||
def current
|
||||
@current ||= begin
|
||||
ArtistCommentaryVersion.where("post_id = ?", post_id).order("updated_at desc").limit(1).to_a
|
||||
end
|
||||
@current ||= ArtistCommentaryVersion.where(post_id: post_id).order("updated_at desc").limit(1).to_a
|
||||
@current.first
|
||||
end
|
||||
|
||||
|
||||
@@ -20,22 +20,22 @@ class ArtistUrl < ApplicationRecord
|
||||
if url.nil?
|
||||
nil
|
||||
else
|
||||
url = url.sub(%r!^https://!, "http://")
|
||||
url = url.sub(%r!^http://blog-imgs-\d+\.fc2!, "http://blog.fc2")
|
||||
url = url.sub(%r!^http://blog-imgs-\d+-\w+\.fc2!, "http://blog.fc2")
|
||||
url = url.sub(%r!^http://blog\d*\.fc2\.com/(?:\w/){,3}(\w+)!, "http://\\1.blog.fc2.com")
|
||||
url = url.sub(%r!^http://pictures.hentai-foundry.com//!, "http://pictures.hentai-foundry.com/")
|
||||
url = url.sub(%r{^https://}, "http://")
|
||||
url = url.sub(%r{^http://blog-imgs-\d+\.fc2}, "http://blog.fc2")
|
||||
url = url.sub(%r{^http://blog-imgs-\d+-\w+\.fc2}, "http://blog.fc2")
|
||||
url = url.sub(%r{^http://blog\d*\.fc2\.com/(?:\w/){,3}(\w+)}, "http://\\1.blog.fc2.com")
|
||||
url = url.sub(%r{^http://pictures.hentai-foundry.com//}, "http://pictures.hentai-foundry.com/")
|
||||
|
||||
# the strategy won't always work for twitter because it looks for a status
|
||||
url = url.downcase if url =~ %r!^https?://(?:mobile\.)?twitter\.com!
|
||||
url = url.downcase if url =~ %r{^https?://(?:mobile\.)?twitter\.com}
|
||||
|
||||
url = Sources::Strategies.find(url).normalize_for_artist_finder
|
||||
|
||||
# XXX the Pixiv strategy should implement normalize_for_artist_finder and return the correct url directly.
|
||||
url = url.sub(%r!\Ahttps?://www\.pixiv\.net/(?:en/)?users/(\d+)\z!i, 'https://www.pixiv.net/member.php?id=\1')
|
||||
url = url.sub(%r{\Ahttps?://www\.pixiv\.net/(?:en/)?users/(\d+)\z}i, 'https://www.pixiv.net/member.php?id=\1')
|
||||
|
||||
url = url.gsub(/\/+\Z/, "")
|
||||
url = url.gsub(%r!^https://!, "http://")
|
||||
url = url.gsub(%r{/+\Z}, "")
|
||||
url = url.gsub(%r{^https://}, "http://")
|
||||
url + "/"
|
||||
end
|
||||
end
|
||||
@@ -60,7 +60,7 @@ class ArtistUrl < ApplicationRecord
|
||||
def self.url_attribute_matches(attr, url)
|
||||
if url.blank?
|
||||
all
|
||||
elsif url =~ %r!\A/(.*)/\z!
|
||||
elsif url =~ %r{\A/(.*)/\z}
|
||||
where_regex(attr, $1)
|
||||
elsif url.include?("*")
|
||||
where_ilike(attr, url)
|
||||
@@ -83,21 +83,21 @@ class ArtistUrl < ApplicationRecord
|
||||
# usually because it's redundant with the primary profile URL.
|
||||
def secondary_url?
|
||||
case url
|
||||
when %r!pixiv\.net/stacc!i
|
||||
when %r{pixiv\.net/stacc}i
|
||||
true
|
||||
when %r!pixiv\.net/fanbox!i
|
||||
when %r{pixiv\.net/fanbox}i
|
||||
true
|
||||
when %r!twitter\.com/intent!i
|
||||
when %r{twitter\.com/intent}i
|
||||
true
|
||||
when %r!lohas\.nicoseiga\.jp!i
|
||||
when %r{lohas\.nicoseiga\.jp}i
|
||||
true
|
||||
when %r!(?:www|com|dic)\.nicovideo\.jp!i
|
||||
when %r{(?:www|com|dic)\.nicovideo\.jp}i
|
||||
true
|
||||
when %r!pawoo\.net/web/accounts!i
|
||||
when %r{pawoo\.net/web/accounts}i
|
||||
true
|
||||
when %r!www\.artstation\.com!i
|
||||
when %r{www\.artstation\.com}i
|
||||
true
|
||||
when %r!blogimg\.jp!i, %r!image\.blog\.livedoor\.jp!i
|
||||
when %r{blogimg\.jp}i, %r{image\.blog\.livedoor\.jp}i
|
||||
true
|
||||
else
|
||||
false
|
||||
@@ -145,15 +145,15 @@ class ArtistUrl < ApplicationRecord
|
||||
end
|
||||
|
||||
def validate_hostname(uri)
|
||||
errors.add(:url, "'#{uri}' has a hostname '#{uri.host}' that does not contain a dot") unless uri.host&.include?('.')
|
||||
errors.add(:url, "'#{uri}' has a hostname '#{uri.host}' that does not contain a dot") unless uri.host&.include?(".")
|
||||
end
|
||||
|
||||
def validate_url_format
|
||||
uri = Addressable::URI.parse(url)
|
||||
validate_scheme(uri)
|
||||
validate_hostname(uri)
|
||||
rescue Addressable::URI::InvalidURIError => error
|
||||
errors.add(:url, "'#{uri}' is malformed: #{error}")
|
||||
rescue Addressable::URI::InvalidURIError => e
|
||||
errors.add(:url, "'#{uri}' is malformed: #{e}")
|
||||
end
|
||||
|
||||
def self.available_includes
|
||||
|
||||
@@ -42,9 +42,7 @@ class ArtistVersion < ApplicationRecord
|
||||
end
|
||||
|
||||
def current
|
||||
@previous ||= begin
|
||||
ArtistVersion.where(artist_id: artist_id).order("created_at desc").limit(1).to_a
|
||||
end
|
||||
@previous ||= ArtistVersion.where(artist_id: artist_id).order("created_at desc").limit(1).to_a
|
||||
@previous.first
|
||||
end
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ class Dmail < ApplicationRecord
|
||||
has_many :moderation_reports, as: :model, dependent: :destroy
|
||||
|
||||
before_create :autoreport_spam
|
||||
after_save :update_unread_dmail_count
|
||||
after_destroy :update_unread_dmail_count
|
||||
after_save :update_unread_dmail_count
|
||||
after_commit :send_email, on: :create
|
||||
|
||||
deletable
|
||||
|
||||
@@ -47,7 +47,7 @@ class DtextLink < ApplicationRecord
|
||||
|
||||
# postgres will raise an error if the link is more than 2712 bytes long
|
||||
# because it can't index values that take up more than 1/3 of an 8kb page.
|
||||
self.link_target = self.link_target.truncate(2048, omission: "")
|
||||
self.link_target = link_target.truncate(2048, omission: "")
|
||||
end
|
||||
|
||||
def self.attribute_restriction(*)
|
||||
|
||||
@@ -48,9 +48,8 @@ class EmailAddress < ApplicationRecord
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :user, :address, :normalized_address, :is_verified, :is_deliverable)
|
||||
|
||||
q = q.restricted(params[:is_restricted])
|
||||
q = q.apply_default_order(params)
|
||||
|
||||
q
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
def validate_deliverable
|
||||
|
||||
@@ -77,7 +77,7 @@ class FavoriteGroup < ApplicationRecord
|
||||
errors.add(:base, "Cannot add invalid post(s) to favgroup: #{nonexisting_post_ids.to_sentence}")
|
||||
end
|
||||
|
||||
duplicate_post_ids = post_ids.group_by(&:itself).transform_values(&:size).select { |id, count| count > 1 }.keys
|
||||
duplicate_post_ids = post_ids.group_by(&:itself).transform_values(&:size).select { |_id, count| count > 1 }.keys
|
||||
if duplicate_post_ids.present?
|
||||
errors.add(:base, "Favgroup already contains post #{duplicate_post_ids.to_sentence}")
|
||||
end
|
||||
@@ -117,7 +117,7 @@ class FavoriteGroup < ApplicationRecord
|
||||
|
||||
def posts
|
||||
favgroup_posts = FavoriteGroup.where(id: id).joins("CROSS JOIN unnest(favorite_groups.post_ids) WITH ORDINALITY AS row(post_id, favgroup_index)").select(:post_id, :favgroup_index)
|
||||
posts = Post.joins("JOIN (#{favgroup_posts.to_sql}) favgroup_posts ON favgroup_posts.post_id = posts.id").order("favgroup_posts.favgroup_index ASC")
|
||||
Post.joins("JOIN (#{favgroup_posts.to_sql}) favgroup_posts ON favgroup_posts.post_id = posts.id").order("favgroup_posts.favgroup_index ASC")
|
||||
end
|
||||
|
||||
def add!(post)
|
||||
|
||||
@@ -179,7 +179,7 @@ class ForumPost < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def dtext_shortlink(**options)
|
||||
def dtext_shortlink(**_options)
|
||||
"forum ##{id}"
|
||||
end
|
||||
|
||||
|
||||
@@ -94,11 +94,12 @@ class ForumTopic < ApplicationRecord
|
||||
q = q.public_only
|
||||
end
|
||||
|
||||
if params[:status] == "pending"
|
||||
case params[:status]
|
||||
when "pending"
|
||||
q = q.pending
|
||||
elsif params[:status] == "approved"
|
||||
when "approved"
|
||||
q = q.approved
|
||||
elsif params[:status] == "rejected"
|
||||
when "rejected"
|
||||
q = q.rejected
|
||||
end
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ class IpAddress < ApplicationRecord
|
||||
ipv4_masklen ||= 32
|
||||
ipv6_masklen ||= 128
|
||||
|
||||
q = select(sanitize_sql([<<~SQL, ipv4_masklen, ipv6_masklen]))
|
||||
q = select(sanitize_sql([<<~SQL.squish, ipv4_masklen, ipv6_masklen]))
|
||||
CASE
|
||||
WHEN family(ip_addr) = 4
|
||||
THEN network(set_masklen(ip_addr, ?))
|
||||
|
||||
@@ -16,8 +16,7 @@ class IpGeolocation < ApplicationRecord
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :ip_addr, :network, :asn, :is_proxy, :latitude, :longitude, :organization, :time_zone, :continent, :country, :region, :city, :carrier)
|
||||
q = q.apply_default_order(params)
|
||||
q
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
def self.create_or_update!(ip)
|
||||
|
||||
@@ -12,8 +12,7 @@ class MediaAsset < ApplicationRecord
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :md5, :file_ext, :file_size, :image_width, :image_height)
|
||||
q = q.apply_default_order(params)
|
||||
q
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
def file=(file_or_path)
|
||||
|
||||
@@ -16,8 +16,7 @@ class MediaMetadata < ApplicationRecord
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :media_asset, :metadata)
|
||||
q = q.apply_default_order(params)
|
||||
q
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
def file=(file_or_path)
|
||||
|
||||
@@ -41,7 +41,7 @@ class ModerationReport < ApplicationRecord
|
||||
if topic.nil?
|
||||
CurrentUser.scoped(User.system) do
|
||||
topic = ForumTopic.create!(creator: User.system, title: forum_topic_title, category_id: 0, min_level: User::Levels::MODERATOR)
|
||||
forum_post = ForumPost.create!(creator: User.system, body: forum_topic_body, topic: topic)
|
||||
ForumPost.create!(creator: User.system, body: forum_topic_body, topic: topic)
|
||||
end
|
||||
end
|
||||
topic
|
||||
|
||||
@@ -13,7 +13,6 @@ class NewsUpdate < ApplicationRecord
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :message, :creator, :updater)
|
||||
q = q.apply_default_order(params)
|
||||
q
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -48,7 +48,7 @@ class Note < ApplicationRecord
|
||||
end
|
||||
|
||||
def update_post
|
||||
if self.saved_changes?
|
||||
if saved_changes?
|
||||
if post.notes.active.exists?
|
||||
post.update_columns(last_noted_at: updated_at)
|
||||
else
|
||||
|
||||
@@ -178,7 +178,7 @@ class Pool < ApplicationRecord
|
||||
# XXX unify with PostQueryBuilder ordpool search
|
||||
def posts
|
||||
pool_posts = Pool.where(id: id).joins("CROSS JOIN unnest(pools.post_ids) WITH ORDINALITY AS row(post_id, pool_index)").select(:post_id, :pool_index)
|
||||
posts = Post.joins("JOIN (#{pool_posts.to_sql}) pool_posts ON pool_posts.post_id = posts.id").order("pool_posts.pool_index ASC")
|
||||
Post.joins("JOIN (#{pool_posts.to_sql}) pool_posts ON pool_posts.post_id = posts.id").order("pool_posts.pool_index ASC")
|
||||
end
|
||||
|
||||
def synchronize
|
||||
|
||||
@@ -78,7 +78,7 @@ class PoolVersion < ApplicationRecord
|
||||
name: pool.name,
|
||||
is_active: pool.is_active?,
|
||||
is_deleted: pool.is_deleted?,
|
||||
category: pool.category
|
||||
category: pool.category,
|
||||
}
|
||||
msg = "add pool version\n#{json.to_json}"
|
||||
sqs_service.send_message(msg, message_group_id: "pool:#{pool.id}")
|
||||
|
||||
@@ -444,7 +444,7 @@ class Post < ApplicationRecord
|
||||
invalid_tags = tag_names.map { |name| Tag.new(name: name) }.select { |tag| tag.invalid?(:name) }
|
||||
|
||||
invalid_tags.each do |tag|
|
||||
tag.errors.messages.each do |attribute, messages|
|
||||
tag.errors.messages.each do |_attribute, messages|
|
||||
warnings.add(:base, "Couldn't add tag: #{messages.join(';')}")
|
||||
end
|
||||
end
|
||||
@@ -524,7 +524,7 @@ class Post < ApplicationRecord
|
||||
when /^newpool:(.+)$/i
|
||||
pool = Pool.find_by_name($1)
|
||||
if pool.nil?
|
||||
pool = Pool.create(name: $1, description: "This pool was automatically generated")
|
||||
Pool.create(name: $1, description: "This pool was automatically generated")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1073,7 +1073,7 @@ class Post < ApplicationRecord
|
||||
"tags" => tag_string,
|
||||
"height" => image_height,
|
||||
"file_size" => file_size,
|
||||
"id" => id
|
||||
"id" => id,
|
||||
}
|
||||
|
||||
if visible?
|
||||
@@ -1148,7 +1148,7 @@ class Post < ApplicationRecord
|
||||
|
||||
def with_flag_stats
|
||||
relation = left_outer_joins(:flags).group(:id).select("posts.*")
|
||||
relation = relation.select("COUNT(post_flags.id) AS flag_count")
|
||||
relation.select("COUNT(post_flags.id) AS flag_count")
|
||||
relation
|
||||
end
|
||||
|
||||
@@ -1308,14 +1308,14 @@ class Post < ApplicationRecord
|
||||
image_width: media_file.width,
|
||||
image_height: media_file.height,
|
||||
file_size: media_file.file_size,
|
||||
file_ext: media_file.file_ext,
|
||||
file_ext: media_file.file_ext
|
||||
)
|
||||
|
||||
media_asset.update!(
|
||||
image_width: media_file.width,
|
||||
image_height: media_file.height,
|
||||
file_size: media_file.file_size,
|
||||
file_ext: media_file.file_ext,
|
||||
file_ext: media_file.file_ext
|
||||
)
|
||||
|
||||
purge_cached_urls!
|
||||
@@ -1328,7 +1328,7 @@ class Post < ApplicationRecord
|
||||
def purge_cached_urls!
|
||||
urls = [
|
||||
preview_file_url, crop_file_url, large_file_url, file_url,
|
||||
tagged_file_url(tagged_filenames: true), tagged_large_file_url(tagged_filenames: true)
|
||||
tagged_file_url(tagged_filenames: true), tagged_large_file_url(tagged_filenames: true),
|
||||
]
|
||||
|
||||
CloudflareService.new.purge_cache(urls)
|
||||
@@ -1519,8 +1519,10 @@ class Post < ApplicationRecord
|
||||
|
||||
def self.available_includes
|
||||
# attributes accessible through the ?only= parameter
|
||||
[:uploader, :updater, :approver, :upload, :flags, :appeals,
|
||||
:parent, :children, :notes, :comments, :approvals, :disapprovals,
|
||||
:replacements, :pixiv_ugoira_frame_data, :artist_commentary]
|
||||
%i[
|
||||
uploader updater approver upload flags appeals parent children notes
|
||||
comments approvals disapprovals replacements pixiv_ugoira_frame_data
|
||||
artist_commentary
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,7 +11,7 @@ class PostFlag < ApplicationRecord
|
||||
validates :reason, presence: true, length: { in: 1..140 }
|
||||
validate :validate_creator_is_not_limited, on: :create
|
||||
validate :validate_post, on: :create
|
||||
validates_uniqueness_of :creator_id, scope: :post_id, on: :create, unless: :is_deletion, message: "have already flagged this post"
|
||||
validates :creator_id, uniqueness: { scope: :post_id, on: :create, unless: :is_deletion, message: "have already flagged this post" }
|
||||
before_save :update_post
|
||||
attr_accessor :is_deletion
|
||||
|
||||
|
||||
@@ -238,7 +238,7 @@ class PostVersion < ApplicationRecord
|
||||
end
|
||||
|
||||
def truncated_source
|
||||
source.gsub(/^http:\/\//, "").sub(/\/.+/, "")
|
||||
source.gsub(%r{^http://}, "").sub(%r{/.+}, "")
|
||||
end
|
||||
|
||||
def undo!
|
||||
|
||||
@@ -17,8 +17,7 @@ class RateLimit < ApplicationRecord
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :limited, :points, :action, :key)
|
||||
q = q.apply_default_order(params)
|
||||
q
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
# `action` is the action being limited. Usually a controller endpoint.
|
||||
@@ -31,7 +30,7 @@ class RateLimit < ApplicationRecord
|
||||
key_params = keys.map.with_index { |key, i| [:"key#{i}", key] }.to_h
|
||||
|
||||
# (created_at, updated_at, action, keyN, points)
|
||||
values = keys.map.with_index { |key, i| "(:now, :now, :action, :key#{i}, :points)" }
|
||||
values = keys.map.with_index { |_key, i| "(:now, :now, :action, :key#{i}, :points)" }
|
||||
|
||||
# Do an upsert, creating a new rate limit object for each key that doesn't
|
||||
# already exist, and updating the limit for each limit that already exists.
|
||||
@@ -43,7 +42,7 @@ class RateLimit < ApplicationRecord
|
||||
# the point count and subtract the cost of the call.
|
||||
#
|
||||
# https://www.postgresql.org/docs/current/sql-insert.html#SQL-ON-CONFLICT
|
||||
sql = <<~SQL
|
||||
sql = <<~SQL.squish
|
||||
INSERT INTO rate_limits (created_at, updated_at, action, key, points)
|
||||
VALUES #{values.join(", ")}
|
||||
ON CONFLICT (action, key) DO UPDATE SET
|
||||
@@ -67,10 +66,9 @@ class RateLimit < ApplicationRecord
|
||||
cost: cost,
|
||||
points: burst - cost,
|
||||
minimum_points: minimum_points,
|
||||
**key_params
|
||||
**key_params,
|
||||
}
|
||||
|
||||
rate_limits = RateLimit.find_by_sql([sql, sql_params])
|
||||
rate_limits
|
||||
RateLimit.find_by_sql([sql, sql_params])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -74,7 +74,7 @@ class Tag < ApplicationRecord
|
||||
|
||||
# fix tags where the post count is non-zero but the tag isn't present on any posts.
|
||||
def regenerate_nonexistent_post_counts!
|
||||
Tag.find_by_sql(<<~SQL)
|
||||
Tag.find_by_sql(<<~SQL.squish)
|
||||
UPDATE tags
|
||||
SET post_count = 0
|
||||
WHERE
|
||||
@@ -90,7 +90,7 @@ class Tag < ApplicationRecord
|
||||
|
||||
# fix tags where the stored post count doesn't match the true post count.
|
||||
def regenerate_incorrect_post_counts!
|
||||
Tag.find_by_sql(<<~SQL)
|
||||
Tag.find_by_sql(<<~SQL.squish)
|
||||
UPDATE tags
|
||||
SET post_count = true_count
|
||||
FROM (
|
||||
@@ -223,7 +223,7 @@ class Tag < ApplicationRecord
|
||||
|
||||
module SearchMethods
|
||||
def autocorrect_matches(name)
|
||||
tags = fuzzy_name_matches(name).order_similarity(name)
|
||||
fuzzy_name_matches(name).order_similarity(name)
|
||||
end
|
||||
|
||||
# ref: https://www.postgresql.org/docs/current/static/pgtrgm.html#idm46428634524336
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class TagAlias < TagRelationship
|
||||
# Validate that the alias doesn't exist yet when it's created or when a BUR
|
||||
# is requested, but not when a BUR is approved (to allow failed BURs to be reapproved)
|
||||
validates_uniqueness_of :antecedent_name, scope: :status, conditions: -> { active }, on: %i[create update request]
|
||||
validates :antecedent_name, uniqueness: { scope: :status, conditions: -> { active }, on: %i[create update request] }
|
||||
validate :absence_of_transitive_relation
|
||||
|
||||
before_create :delete_conflicting_relationships
|
||||
|
||||
@@ -215,7 +215,9 @@ class Upload < ApplicationRecord
|
||||
end
|
||||
|
||||
def assign_rating_from_tags
|
||||
if rating = PostQueryBuilder.new(tag_string).find_metatag(:rating)
|
||||
rating = PostQueryBuilder.new(tag_string).find_metatag(:rating)
|
||||
|
||||
if rating.present?
|
||||
self.rating = rating.downcase.first
|
||||
end
|
||||
end
|
||||
|
||||
@@ -33,8 +33,7 @@ class UserEvent < ApplicationRecord
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :category, :user, :user_session)
|
||||
q = q.apply_default_order(params)
|
||||
q
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
def self.available_includes
|
||||
|
||||
@@ -97,8 +97,7 @@ class UserUpgrade < ApplicationRecord
|
||||
q = q.self_upgrade
|
||||
end
|
||||
|
||||
q = q.apply_default_order(params)
|
||||
q
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
concerning :UpgradeMethods do
|
||||
|
||||
Reference in New Issue
Block a user