Autofix Rubocop Style/RedundantBegin (#23703)
This commit is contained in:
parent
167709f6b0
commit
2177daeae9
69 changed files with 458 additions and 695 deletions
|
@ -2958,79 +2958,6 @@ Style/RedundantArgument:
|
|||
- 'app/helpers/application_helper.rb'
|
||||
- 'lib/tasks/emojis.rake'
|
||||
|
||||
# Offense count: 83
|
||||
# This cop supports safe autocorrection (--autocorrect).
|
||||
Style/RedundantBegin:
|
||||
Exclude:
|
||||
- 'app/controllers/admin/dashboard_controller.rb'
|
||||
- 'app/controllers/api/v1/announcements_controller.rb'
|
||||
- 'app/controllers/api/v1/trends/links_controller.rb'
|
||||
- 'app/controllers/api/v1/trends/statuses_controller.rb'
|
||||
- 'app/controllers/api/v1/trends/tags_controller.rb'
|
||||
- 'app/controllers/concerns/rate_limit_headers.rb'
|
||||
- 'app/controllers/concerns/two_factor_authentication_concern.rb'
|
||||
- 'app/helpers/admin/dashboard_helper.rb'
|
||||
- 'app/helpers/admin/trends/statuses_helper.rb'
|
||||
- 'app/helpers/branding_helper.rb'
|
||||
- 'app/helpers/domain_control_helper.rb'
|
||||
- 'app/helpers/formatting_helper.rb'
|
||||
- 'app/helpers/instance_helper.rb'
|
||||
- 'app/helpers/jsonld_helper.rb'
|
||||
- 'app/lib/activity_tracker.rb'
|
||||
- 'app/lib/activitypub/activity/create.rb'
|
||||
- 'app/lib/activitypub/forwarder.rb'
|
||||
- 'app/lib/admin/metrics/dimension/software_versions_dimension.rb'
|
||||
- 'app/lib/admin/metrics/dimension/space_usage_dimension.rb'
|
||||
- 'app/lib/extractor.rb'
|
||||
- 'app/lib/importer/statuses_index_importer.rb'
|
||||
- 'app/lib/link_details_extractor.rb'
|
||||
- 'app/lib/request.rb'
|
||||
- 'app/models/account.rb'
|
||||
- 'app/models/account/field.rb'
|
||||
- 'app/models/admin/account_action.rb'
|
||||
- 'app/models/announcement.rb'
|
||||
- 'app/models/concerns/account_merging.rb'
|
||||
- 'app/models/concerns/pam_authenticable.rb'
|
||||
- 'app/models/email_domain_block.rb'
|
||||
- 'app/models/form/admin_settings.rb'
|
||||
- 'app/models/form/custom_emoji_batch.rb'
|
||||
- 'app/models/notification.rb'
|
||||
- 'app/models/remote_follow.rb'
|
||||
- 'app/models/status.rb'
|
||||
- 'app/models/status_edit.rb'
|
||||
- 'app/models/trends/links.rb'
|
||||
- 'app/models/trends/statuses.rb'
|
||||
- 'app/models/trends/tag_filter.rb'
|
||||
- 'app/models/trends/tags.rb'
|
||||
- 'app/models/web/push_subscription.rb'
|
||||
- 'app/presenters/tag_relationships_presenter.rb'
|
||||
- 'app/services/account_search_service.rb'
|
||||
- 'app/services/activitypub/fetch_featured_tags_collection_service.rb'
|
||||
- 'app/services/activitypub/fetch_remote_status_service.rb'
|
||||
- 'app/services/fetch_link_card_service.rb'
|
||||
- 'app/services/process_mentions_service.rb'
|
||||
- 'app/services/reblog_service.rb'
|
||||
- 'app/services/resolve_account_service.rb'
|
||||
- 'app/validators/domain_validator.rb'
|
||||
- 'app/validators/existing_username_validator.rb'
|
||||
- 'app/validators/import_validator.rb'
|
||||
- 'app/workers/backup_worker.rb'
|
||||
- 'app/workers/post_process_media_worker.rb'
|
||||
- 'app/workers/scheduler/follow_recommendations_scheduler.rb'
|
||||
- 'db/migrate/20180528141303_fix_accounts_unique_index.rb'
|
||||
- 'db/migrate/20180812173710_copy_status_stats.rb'
|
||||
- 'db/migrate/20181116173541_copy_account_stats.rb'
|
||||
- 'lib/mastodon/accounts_cli.rb'
|
||||
- 'lib/mastodon/cli_helper.rb'
|
||||
- 'lib/mastodon/ip_blocks_cli.rb'
|
||||
- 'lib/mastodon/maintenance_cli.rb'
|
||||
- 'lib/mastodon/media_cli.rb'
|
||||
- 'lib/mastodon/search_cli.rb'
|
||||
- 'lib/mastodon/upgrade_cli.rb'
|
||||
- 'lib/paperclip/color_extractor.rb'
|
||||
- 'lib/sanitize_ext/sanitize_config.rb'
|
||||
- 'lib/tasks/db.rake'
|
||||
|
||||
# Offense count: 16
|
||||
# This cop supports safe autocorrection (--autocorrect).
|
||||
Style/RedundantRegexpCharacterClass:
|
||||
|
|
|
@ -18,8 +18,7 @@ module Admin
|
|||
private
|
||||
|
||||
def redis_info
|
||||
@redis_info ||= begin
|
||||
if redis.is_a?(Redis::Namespace)
|
||||
@redis_info ||= if redis.is_a?(Redis::Namespace)
|
||||
redis.redis.info
|
||||
else
|
||||
redis.info
|
||||
|
@ -27,4 +26,3 @@ module Admin
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,9 +18,7 @@ class Api::V1::AnnouncementsController < Api::BaseController
|
|||
private
|
||||
|
||||
def set_announcements
|
||||
@announcements = begin
|
||||
Announcement.published.chronological
|
||||
end
|
||||
@announcements = Announcement.published.chronological
|
||||
end
|
||||
|
||||
def set_announcement
|
||||
|
|
|
@ -18,14 +18,12 @@ class Api::V1::Trends::LinksController < Api::BaseController
|
|||
end
|
||||
|
||||
def set_links
|
||||
@links = begin
|
||||
if enabled?
|
||||
@links = if enabled?
|
||||
links_from_trends.offset(offset_param).limit(limit_param(DEFAULT_LINKS_LIMIT))
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def links_from_trends
|
||||
scope = Trends.links.query.allowed.in_locale(content_locale)
|
||||
|
|
|
@ -16,14 +16,12 @@ class Api::V1::Trends::StatusesController < Api::BaseController
|
|||
end
|
||||
|
||||
def set_statuses
|
||||
@statuses = begin
|
||||
if enabled?
|
||||
@statuses = if enabled?
|
||||
cache_collection(statuses_from_trends.offset(offset_param).limit(limit_param(DEFAULT_STATUSES_LIMIT)), Status)
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def statuses_from_trends
|
||||
scope = Trends.statuses.query.allowed.in_locale(content_locale)
|
||||
|
|
|
@ -18,14 +18,12 @@ class Api::V1::Trends::TagsController < Api::BaseController
|
|||
end
|
||||
|
||||
def set_tags
|
||||
@tags = begin
|
||||
if enabled?
|
||||
@tags = if enabled?
|
||||
tags_from_trends.offset(offset_param).limit(limit_param(DEFAULT_TAGS_LIMIT))
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def tags_from_trends
|
||||
Trends.tags.query.allowed
|
||||
|
|
|
@ -6,7 +6,6 @@ module RateLimitHeaders
|
|||
class_methods do
|
||||
def override_rate_limit_headers(method_name, options = {})
|
||||
around_action(only: method_name, if: :current_account) do |_controller, block|
|
||||
begin
|
||||
block.call
|
||||
ensure
|
||||
rate_limiter = RateLimiter.new(current_account, options)
|
||||
|
@ -15,7 +14,6 @@ module RateLimitHeaders
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
included do
|
||||
before_action :set_rate_limit_headers, if: :rate_limited_request?
|
||||
|
|
|
@ -79,13 +79,11 @@ module TwoFactorAuthenticationConcern
|
|||
|
||||
@body_classes = 'lighter'
|
||||
@webauthn_enabled = user.webauthn_enabled?
|
||||
@scheme_type = begin
|
||||
if user.webauthn_enabled? && user_params[:otp_attempt].blank?
|
||||
@scheme_type = if user.webauthn_enabled? && user_params[:otp_attempt].blank?
|
||||
'webauthn'
|
||||
else
|
||||
'totp'
|
||||
end
|
||||
end
|
||||
|
||||
set_locale { render :two_factor }
|
||||
end
|
||||
|
|
|
@ -19,8 +19,7 @@ module Admin::DashboardHelper
|
|||
end
|
||||
|
||||
def relevant_account_timestamp(account)
|
||||
timestamp, exact = begin
|
||||
if account.user_current_sign_in_at && account.user_current_sign_in_at < 24.hours.ago
|
||||
timestamp, exact = if account.user_current_sign_in_at && account.user_current_sign_in_at < 24.hours.ago
|
||||
[account.user_current_sign_in_at, true]
|
||||
elsif account.user_current_sign_in_at
|
||||
[account.user_current_sign_in_at, false]
|
||||
|
@ -31,7 +30,6 @@ module Admin::DashboardHelper
|
|||
else
|
||||
[nil, false]
|
||||
end
|
||||
end
|
||||
|
||||
return '-' if timestamp.nil?
|
||||
return t('generic.today') unless exact
|
||||
|
|
|
@ -2,13 +2,11 @@
|
|||
|
||||
module Admin::Trends::StatusesHelper
|
||||
def one_line_preview(status)
|
||||
text = begin
|
||||
if status.local?
|
||||
text = if status.local?
|
||||
status.text.split("\n").first
|
||||
else
|
||||
Nokogiri::HTML(status.text).css('html > body > *').first&.text
|
||||
end
|
||||
end
|
||||
|
||||
return '' if text.blank?
|
||||
|
||||
|
|
|
@ -23,14 +23,12 @@ module BrandingHelper
|
|||
end
|
||||
|
||||
def render_symbol(version = :icon)
|
||||
path = begin
|
||||
case version
|
||||
path = case version
|
||||
when :icon
|
||||
'logo-symbol-icon.svg'
|
||||
when :wordmark
|
||||
'logo-symbol-wordmark.svg'
|
||||
end
|
||||
end
|
||||
|
||||
render(file: Rails.root.join('app', 'javascript', 'images', path)).html_safe # rubocop:disable Rails/OutputSafety
|
||||
end
|
||||
|
|
|
@ -4,13 +4,11 @@ module DomainControlHelper
|
|||
def domain_not_allowed?(uri_or_domain)
|
||||
return if uri_or_domain.blank?
|
||||
|
||||
domain = begin
|
||||
if uri_or_domain.include?('://')
|
||||
domain = if uri_or_domain.include?('://')
|
||||
Addressable::URI.parse(uri_or_domain).host
|
||||
else
|
||||
uri_or_domain
|
||||
end
|
||||
end
|
||||
|
||||
if whitelist_mode?
|
||||
!DomainAllow.allowed?(domain)
|
||||
|
|
|
@ -21,8 +21,7 @@ module FormattingHelper
|
|||
def rss_status_content_format(status)
|
||||
html = status_content_format(status)
|
||||
|
||||
before_html = begin
|
||||
if status.spoiler_text?
|
||||
before_html = if status.spoiler_text?
|
||||
tag.p do
|
||||
tag.strong do
|
||||
I18n.t('rss.content_warning', locale: available_locale_or_nil(status.language) || I18n.default_locale)
|
||||
|
@ -31,10 +30,8 @@ module FormattingHelper
|
|||
status.spoiler_text
|
||||
end + tag.hr
|
||||
end
|
||||
end
|
||||
|
||||
after_html = begin
|
||||
if status.preloadable_poll
|
||||
after_html = if status.preloadable_poll
|
||||
tag.p do
|
||||
safe_join(
|
||||
status.preloadable_poll.options.map do |o|
|
||||
|
@ -44,7 +41,6 @@ module FormattingHelper
|
|||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
prerender_custom_emojis(
|
||||
safe_join([before_html, html, after_html]),
|
||||
|
|
|
@ -10,13 +10,11 @@ module InstanceHelper
|
|||
end
|
||||
|
||||
def description_for_sign_up
|
||||
prefix = begin
|
||||
if @invite.present?
|
||||
prefix = if @invite.present?
|
||||
I18n.t('auth.description.prefix_invited_by_user', name: @invite.user.account.username)
|
||||
else
|
||||
I18n.t('auth.description.prefix_sign_up')
|
||||
end
|
||||
end
|
||||
|
||||
safe_join([prefix, I18n.t('auth.description.suffix')], ' ')
|
||||
end
|
||||
|
|
|
@ -26,15 +26,13 @@ module JsonLdHelper
|
|||
# The url attribute can be a string, an array of strings, or an array of objects.
|
||||
# The objects could include a mimeType. Not-included mimeType means it's text/html.
|
||||
def url_to_href(value, preferred_type = nil)
|
||||
single_value = begin
|
||||
if value.is_a?(Array) && !value.first.is_a?(String)
|
||||
single_value = if value.is_a?(Array) && !value.first.is_a?(String)
|
||||
value.find { |link| preferred_type.nil? || ((link['mimeType'].presence || 'text/html') == preferred_type) }
|
||||
elsif value.is_a?(Array)
|
||||
value.first
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
if single_value.nil? || single_value.is_a?(String)
|
||||
single_value
|
||||
|
|
|
@ -27,14 +27,12 @@ class ActivityTracker
|
|||
(start_at.to_date...end_at.to_date).map do |date|
|
||||
key = key_at(date.to_time(:utc))
|
||||
|
||||
value = begin
|
||||
case @type
|
||||
value = case @type
|
||||
when :basic
|
||||
redis.get(key).to_i
|
||||
when :unique
|
||||
redis.pfcount(key)
|
||||
end
|
||||
end
|
||||
|
||||
[date, value]
|
||||
end
|
||||
|
|
|
@ -108,8 +108,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
def process_status_params
|
||||
@status_parser = ActivityPub::Parser::StatusParser.new(@json, followers_collection: @account.followers_url)
|
||||
|
||||
@params = begin
|
||||
{
|
||||
@params = {
|
||||
uri: @status_parser.uri,
|
||||
url: @status_parser.url || @status_parser.uri,
|
||||
account: @account,
|
||||
|
@ -128,7 +127,6 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
poll: process_poll,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def process_audience
|
||||
# Unlike with tags, there is no point in resolving accounts we don't already
|
||||
|
|
|
@ -28,14 +28,12 @@ class ActivityPub::Forwarder
|
|||
end
|
||||
|
||||
def signature_account_id
|
||||
@signature_account_id ||= begin
|
||||
if in_reply_to_local?
|
||||
@signature_account_id ||= if in_reply_to_local?
|
||||
in_reply_to.account_id
|
||||
else
|
||||
reblogged_by_account_ids.first
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def inboxes
|
||||
@inboxes ||= begin
|
||||
|
|
|
@ -58,12 +58,10 @@ class Admin::Metrics::Dimension::SoftwareVersionsDimension < Admin::Metrics::Dim
|
|||
end
|
||||
|
||||
def redis_info
|
||||
@redis_info ||= begin
|
||||
if redis.is_a?(Redis::Namespace)
|
||||
@redis_info ||= if redis.is_a?(Redis::Namespace)
|
||||
redis.redis.info
|
||||
else
|
||||
redis.info
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -59,12 +59,10 @@ class Admin::Metrics::Dimension::SpaceUsageDimension < Admin::Metrics::Dimension
|
|||
end
|
||||
|
||||
def redis_info
|
||||
@redis_info ||= begin
|
||||
if redis.is_a?(Redis::Namespace)
|
||||
@redis_info ||= if redis.is_a?(Redis::Namespace)
|
||||
redis.redis.info
|
||||
else
|
||||
redis.info
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,12 +8,10 @@ module Extractor
|
|||
module_function
|
||||
|
||||
def extract_entities_with_indices(text, options = {}, &block)
|
||||
entities = begin
|
||||
extract_urls_with_indices(text, options) +
|
||||
entities = extract_urls_with_indices(text, options) +
|
||||
extract_hashtags_with_indices(text, check_url_overlap: false) +
|
||||
extract_mentions_or_lists_with_indices(text) +
|
||||
extract_extra_uris_with_indices(text)
|
||||
end
|
||||
|
||||
return [] if entities.empty?
|
||||
|
||||
|
|
|
@ -24,13 +24,11 @@ class Importer::StatusesIndexImporter < Importer::BaseImporter
|
|||
# is called before rendering the data and we need to filter based
|
||||
# on the results of the filter, so this filtering happens here instead
|
||||
bulk.map! do |entry|
|
||||
new_entry = begin
|
||||
if entry[:index] && entry.dig(:index, :data, 'searchable_by').blank?
|
||||
new_entry = if entry[:index] && entry.dig(:index, :data, 'searchable_by').blank?
|
||||
{ delete: entry[:index].except(:data) }
|
||||
else
|
||||
entry
|
||||
end
|
||||
end
|
||||
|
||||
if new_entry[:index]
|
||||
indexed += 1
|
||||
|
|
|
@ -232,12 +232,11 @@ class LinkDetailsExtractor
|
|||
end
|
||||
|
||||
def structured_data
|
||||
@structured_data ||= begin
|
||||
# Some publications have more than one JSON-LD definition on the page,
|
||||
# and some of those definitions aren't valid JSON either, so we have
|
||||
# to loop through here until we find something that is the right type
|
||||
# and doesn't break
|
||||
document.xpath('//script[@type="application/ld+json"]').filter_map do |element|
|
||||
@structured_data ||= document.xpath('//script[@type="application/ld+json"]').filter_map do |element|
|
||||
json_ld = element.content&.gsub(CDATA_JUNK_PATTERN, '')
|
||||
|
||||
next if json_ld.blank?
|
||||
|
@ -252,7 +251,6 @@ class LinkDetailsExtractor
|
|||
next
|
||||
end.first
|
||||
end
|
||||
end
|
||||
|
||||
def document
|
||||
@document ||= Nokogiri::HTML(@html, nil, encoding)
|
||||
|
|
|
@ -215,7 +215,6 @@ class Request
|
|||
addr_by_socket = {}
|
||||
|
||||
addresses.each do |address|
|
||||
begin
|
||||
check_private_address(address, host)
|
||||
|
||||
sock = ::Socket.new(address.is_a?(Resolv::IPv6) ? ::Socket::AF_INET6 : ::Socket::AF_INET, ::Socket::SOCK_STREAM, 0)
|
||||
|
@ -235,7 +234,6 @@ class Request
|
|||
rescue => e
|
||||
outer_e = e
|
||||
end
|
||||
end
|
||||
|
||||
until socks.empty?
|
||||
_, available_socks, = IO.select(nil, socks, nil, Request::TIMEOUT[:connect])
|
||||
|
@ -279,9 +277,7 @@ class Request
|
|||
end
|
||||
|
||||
def private_address_exceptions
|
||||
@private_address_exceptions = begin
|
||||
(ENV['ALLOWED_PRIVATE_ADDRESSES'] || '').split(',').map { |addr| IPAddr.new(addr) }
|
||||
end
|
||||
@private_address_exceptions = (ENV['ALLOWED_PRIVATE_ADDRESSES'] || '').split(',').map { |addr| IPAddr.new(addr) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -459,13 +459,12 @@ class Account < ApplicationRecord
|
|||
return [] if text.blank?
|
||||
|
||||
text.scan(MENTION_RE).map { |match| match.first.split('@', 2) }.uniq.filter_map do |(username, domain)|
|
||||
domain = begin
|
||||
if TagManager.instance.local_domain?(domain)
|
||||
domain = if TagManager.instance.local_domain?(domain)
|
||||
nil
|
||||
else
|
||||
TagManager.instance.normalize_domain(domain)
|
||||
end
|
||||
end
|
||||
|
||||
EntityCache.instance.mention(username, domain)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,14 +25,12 @@ class Account::Field < ActiveModelSerializers::Model
|
|||
end
|
||||
|
||||
def value_for_verification
|
||||
@value_for_verification ||= begin
|
||||
if account.local?
|
||||
@value_for_verification ||= if account.local?
|
||||
value
|
||||
else
|
||||
extract_url_from_html
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def verifiable?
|
||||
return false if value_for_verification.blank?
|
||||
|
|
|
@ -166,14 +166,12 @@ class Admin::AccountAction
|
|||
end
|
||||
|
||||
def reports
|
||||
@reports ||= begin
|
||||
if type == 'none'
|
||||
@reports ||= if type == 'none'
|
||||
with_report? ? [report] : []
|
||||
else
|
||||
Report.where(target_account: target_account).unresolved
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def warning_preset
|
||||
@warning_preset ||= AccountWarningPreset.find(warning_preset_id) if warning_preset_id.present?
|
||||
|
|
|
@ -54,14 +54,12 @@ class Announcement < ApplicationRecord
|
|||
end
|
||||
|
||||
def statuses
|
||||
@statuses ||= begin
|
||||
if status_ids.nil?
|
||||
@statuses ||= if status_ids.nil?
|
||||
[]
|
||||
else
|
||||
Status.where(id: status_ids, visibility: [:public, :unlisted])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def tags
|
||||
@tags ||= Tag.find_or_create_by_names(Extractor.extract_hashtags(text))
|
||||
|
|
|
@ -21,13 +21,11 @@ module AccountMerging
|
|||
|
||||
owned_classes.each do |klass|
|
||||
klass.where(account_id: other_account.id).find_each do |record|
|
||||
begin
|
||||
record.update_attribute(:account_id, id)
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
next
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
target_classes = [
|
||||
Follow, FollowRequest, Block, Mute, AccountModerationNote, AccountPin,
|
||||
|
@ -36,13 +34,11 @@ module AccountMerging
|
|||
|
||||
target_classes.each do |klass|
|
||||
klass.where(target_account_id: other_account.id).find_each do |record|
|
||||
begin
|
||||
record.update_attribute(:target_account_id, id)
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
next
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
CanonicalEmailBlock.where(reference_account_id: other_account.id).find_each do |record|
|
||||
record.update_attribute(:reference_account_id, id)
|
||||
|
|
|
@ -42,13 +42,11 @@ module PamAuthenticable
|
|||
def self.pam_get_user(attributes = {})
|
||||
return nil unless attributes[:email]
|
||||
|
||||
resource = begin
|
||||
if Devise.check_at_sign && !attributes[:email].index('@')
|
||||
resource = if Devise.check_at_sign && !attributes[:email].index('@')
|
||||
joins(:account).find_by(accounts: { username: attributes[:email] })
|
||||
else
|
||||
find_by(email: attributes[:email])
|
||||
end
|
||||
end
|
||||
|
||||
if resource.nil?
|
||||
resource = new(email: attributes[:email], agreement: true)
|
||||
|
|
|
@ -69,13 +69,11 @@ class EmailDomainBlock < ApplicationRecord
|
|||
|
||||
def extract_uris(domain_or_domains)
|
||||
Array(domain_or_domains).map do |str|
|
||||
domain = begin
|
||||
if str.include?('@')
|
||||
domain = if str.include?('@')
|
||||
str.split('@', 2).last
|
||||
else
|
||||
str
|
||||
end
|
||||
end
|
||||
|
||||
Addressable::URI.new.tap { |u| u.host = domain.strip } if domain.present?
|
||||
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
|
||||
|
|
|
@ -76,13 +76,11 @@ class Form::AdminSettings
|
|||
define_method(key) do
|
||||
return instance_variable_get("@#{key}") if instance_variable_defined?("@#{key}")
|
||||
|
||||
stored_value = begin
|
||||
if UPLOAD_KEYS.include?(key)
|
||||
stored_value = if UPLOAD_KEYS.include?(key)
|
||||
SiteUpload.where(var: key).first_or_initialize(var: key)
|
||||
else
|
||||
Setting.public_send(key)
|
||||
end
|
||||
end
|
||||
|
||||
instance_variable_set("@#{key}", stored_value)
|
||||
end
|
||||
|
|
|
@ -36,13 +36,11 @@ class Form::CustomEmojiBatch
|
|||
def update!
|
||||
custom_emojis.each { |custom_emoji| authorize(custom_emoji, :update?) }
|
||||
|
||||
category = begin
|
||||
if category_id.present?
|
||||
category = if category_id.present?
|
||||
CustomEmojiCategory.find(category_id)
|
||||
elsif category_name.present?
|
||||
CustomEmojiCategory.find_or_create_by!(name: category_name)
|
||||
end
|
||||
end
|
||||
|
||||
custom_emojis.each do |custom_emoji|
|
||||
custom_emoji.update(category_id: category&.id)
|
||||
|
|
|
@ -87,13 +87,11 @@ class Notification < ApplicationRecord
|
|||
|
||||
class << self
|
||||
def browserable(types: [], exclude_types: [], from_account_id: nil)
|
||||
requested_types = begin
|
||||
if types.empty?
|
||||
requested_types = if types.empty?
|
||||
TYPES
|
||||
else
|
||||
types.map(&:to_sym) & TYPES
|
||||
end
|
||||
end
|
||||
|
||||
requested_types -= exclude_types.map(&:to_sym)
|
||||
|
||||
|
|
|
@ -36,13 +36,11 @@ class RemoteFollow
|
|||
|
||||
username, domain = value.strip.gsub(/\A@/, '').split('@')
|
||||
|
||||
domain = begin
|
||||
if TagManager.instance.local_domain?(domain)
|
||||
domain = if TagManager.instance.local_domain?(domain)
|
||||
nil
|
||||
else
|
||||
TagManager.instance.normalize_domain(domain)
|
||||
end
|
||||
end
|
||||
|
||||
[username, domain].compact.join('@')
|
||||
rescue Addressable::URI::InvalidURIError
|
||||
|
|
|
@ -368,13 +368,12 @@ class Status < ApplicationRecord
|
|||
return [] if text.blank?
|
||||
|
||||
text.scan(FetchLinkCardService::URL_PATTERN).map(&:second).uniq.filter_map do |url|
|
||||
status = begin
|
||||
if TagManager.instance.local_url?(url)
|
||||
status = if TagManager.instance.local_url?(url)
|
||||
ActivityPub::TagManager.instance.uri_to_resource(url, Status)
|
||||
else
|
||||
EntityCache.instance.status(url)
|
||||
end
|
||||
end
|
||||
|
||||
status&.distributable? ? status : nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -51,15 +51,13 @@ class StatusEdit < ApplicationRecord
|
|||
def ordered_media_attachments
|
||||
return @ordered_media_attachments if defined?(@ordered_media_attachments)
|
||||
|
||||
@ordered_media_attachments = begin
|
||||
if ordered_media_attachment_ids.nil?
|
||||
@ordered_media_attachments = if ordered_media_attachment_ids.nil?
|
||||
[]
|
||||
else
|
||||
map = status.media_attachments.index_by(&:id)
|
||||
ordered_media_attachment_ids.map.with_index { |media_attachment_id, index| PreservedMediaAttachment.new(media_attachment: map[media_attachment_id], description: media_descriptions[index]) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def proper
|
||||
self
|
||||
|
|
|
@ -113,13 +113,11 @@ class Trends::Links < Trends::Base
|
|||
max_score = preview_card.max_score
|
||||
max_score = 0 if max_time.nil? || max_time < (at_time - options[:max_score_cooldown])
|
||||
|
||||
score = begin
|
||||
if expected > observed || observed < options[:threshold]
|
||||
score = if expected > observed || observed < options[:threshold]
|
||||
0
|
||||
else
|
||||
((observed - expected)**2) / expected
|
||||
end
|
||||
end
|
||||
|
||||
if score > max_score
|
||||
max_score = score
|
||||
|
@ -129,13 +127,11 @@ class Trends::Links < Trends::Base
|
|||
preview_card.update_columns(max_score: max_score, max_score_at: max_time)
|
||||
end
|
||||
|
||||
decaying_score = begin
|
||||
if max_score.zero? || !valid_locale?(preview_card.language)
|
||||
decaying_score = if max_score.zero? || !valid_locale?(preview_card.language)
|
||||
0
|
||||
else
|
||||
max_score * (0.5**((at_time.to_f - max_time.to_f) / options[:max_score_halflife].to_f))
|
||||
end
|
||||
end
|
||||
|
||||
[decaying_score, preview_card]
|
||||
end
|
||||
|
|
|
@ -99,21 +99,17 @@ class Trends::Statuses < Trends::Base
|
|||
expected = 1.0
|
||||
observed = (status.reblogs_count + status.favourites_count).to_f
|
||||
|
||||
score = begin
|
||||
if expected > observed || observed < options[:threshold]
|
||||
score = if expected > observed || observed < options[:threshold]
|
||||
0
|
||||
else
|
||||
((observed - expected)**2) / expected
|
||||
end
|
||||
end
|
||||
|
||||
decaying_score = begin
|
||||
if score.zero? || !eligible?(status)
|
||||
decaying_score = if score.zero? || !eligible?(status)
|
||||
0
|
||||
else
|
||||
score * (0.5**((at_time.to_f - status.created_at.to_f) / options[:score_halflife].to_f))
|
||||
end
|
||||
end
|
||||
|
||||
[decaying_score, status]
|
||||
end
|
||||
|
|
|
@ -13,13 +13,11 @@ class Trends::TagFilter
|
|||
end
|
||||
|
||||
def results
|
||||
scope = begin
|
||||
if params[:status] == 'pending_review'
|
||||
scope = if params[:status] == 'pending_review'
|
||||
Tag.unscoped
|
||||
else
|
||||
trending_scope
|
||||
end
|
||||
end
|
||||
|
||||
params.each do |key, value|
|
||||
next if key.to_s == 'page'
|
||||
|
|
|
@ -63,13 +63,11 @@ class Trends::Tags < Trends::Base
|
|||
max_score = tag.max_score
|
||||
max_score = 0 if max_time.nil? || max_time < (at_time - options[:max_score_cooldown])
|
||||
|
||||
score = begin
|
||||
if expected > observed || observed < options[:threshold]
|
||||
score = if expected > observed || observed < options[:threshold]
|
||||
0
|
||||
else
|
||||
((observed - expected)**2) / expected
|
||||
end
|
||||
end
|
||||
|
||||
if score > max_score
|
||||
max_score = score
|
||||
|
|
|
@ -53,26 +53,22 @@ class Web::PushSubscription < ApplicationRecord
|
|||
def associated_user
|
||||
return @associated_user if defined?(@associated_user)
|
||||
|
||||
@associated_user = begin
|
||||
if user_id.nil?
|
||||
@associated_user = if user_id.nil?
|
||||
session_activation.user
|
||||
else
|
||||
user
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def associated_access_token
|
||||
return @associated_access_token if defined?(@associated_access_token)
|
||||
|
||||
@associated_access_token = begin
|
||||
if access_token_id.nil?
|
||||
@associated_access_token = if access_token_id.nil?
|
||||
find_or_create_access_token.token
|
||||
else
|
||||
access_token.token
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class << self
|
||||
def unsubscribe_for(application_id, resource_owner)
|
||||
|
|
|
@ -4,12 +4,10 @@ class TagRelationshipsPresenter
|
|||
attr_reader :following_map
|
||||
|
||||
def initialize(tags, current_account_id = nil, **options)
|
||||
@following_map = begin
|
||||
if current_account_id.nil?
|
||||
@following_map = if current_account_id.nil?
|
||||
{}
|
||||
else
|
||||
TagFollow.select(:tag_id).where(tag_id: tags.map(&:id), account_id: current_account_id).each_with_object({}) { |f, h| h[f.tag_id] = true }.merge(options[:following_map] || {})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -32,15 +32,13 @@ class AccountSearchService < BaseService
|
|||
|
||||
return @exact_match if defined?(@exact_match)
|
||||
|
||||
match = begin
|
||||
if options[:resolve]
|
||||
match = if options[:resolve]
|
||||
ResolveAccountService.new.call(query)
|
||||
elsif domain_is_local?
|
||||
Account.find_local(query_username)
|
||||
else
|
||||
Account.find_remote(query_username, query_domain)
|
||||
end
|
||||
end
|
||||
|
||||
match = nil if !match.nil? && !account.nil? && options[:following] && !account.following?(match)
|
||||
|
||||
|
|
|
@ -22,14 +22,12 @@ class ActivityPub::FetchFeaturedTagsCollectionService < BaseService
|
|||
collection = fetch_collection(collection['first']) if collection['first'].present?
|
||||
|
||||
while collection.is_a?(Hash)
|
||||
items = begin
|
||||
case collection['type']
|
||||
items = case collection['type']
|
||||
when 'Collection', 'CollectionPage'
|
||||
collection['items']
|
||||
when 'OrderedCollection', 'OrderedCollectionPage'
|
||||
collection['orderedItems']
|
||||
end
|
||||
end
|
||||
|
||||
break if items.blank?
|
||||
|
||||
|
|
|
@ -9,13 +9,11 @@ class ActivityPub::FetchRemoteStatusService < BaseService
|
|||
# Should be called when uri has already been checked for locality
|
||||
def call(uri, id: true, prefetched_body: nil, on_behalf_of: nil, expected_actor_uri: nil, request_id: nil)
|
||||
@request_id = request_id || "#{Time.now.utc.to_i}-status-#{uri}"
|
||||
@json = begin
|
||||
if prefetched_body.nil?
|
||||
@json = if prefetched_body.nil?
|
||||
fetch_resource(uri, id, on_behalf_of)
|
||||
else
|
||||
body_to_json(prefetched_body, compare_id: id ? uri : nil)
|
||||
end
|
||||
end
|
||||
|
||||
return unless supported_context?
|
||||
|
||||
|
|
|
@ -69,8 +69,7 @@ class FetchLinkCardService < BaseService
|
|||
end
|
||||
|
||||
def parse_urls
|
||||
urls = begin
|
||||
if @status.local?
|
||||
urls = if @status.local?
|
||||
@status.text.scan(URL_PATTERN).map { |array| Addressable::URI.parse(array[1]).normalize }
|
||||
else
|
||||
document = Nokogiri::HTML(@status.text)
|
||||
|
@ -78,7 +77,6 @@ class FetchLinkCardService < BaseService
|
|||
|
||||
links.filter_map { |a| Addressable::URI.parse(a['href']) unless skip_link?(a) }.filter_map(&:normalize)
|
||||
end
|
||||
end
|
||||
|
||||
urls.reject { |uri| bad_url?(uri) }.first
|
||||
end
|
||||
|
|
|
@ -28,13 +28,11 @@ class ProcessMentionsService < BaseService
|
|||
@status.text = @status.text.gsub(Account::MENTION_RE) do |match|
|
||||
username, domain = Regexp.last_match(1).split('@')
|
||||
|
||||
domain = begin
|
||||
if TagManager.instance.local_domain?(domain)
|
||||
domain = if TagManager.instance.local_domain?(domain)
|
||||
nil
|
||||
else
|
||||
TagManager.instance.normalize_domain(domain)
|
||||
end
|
||||
end
|
||||
|
||||
mentioned_account = Account.find_remote(username, domain)
|
||||
|
||||
|
|
|
@ -20,13 +20,11 @@ class ReblogService < BaseService
|
|||
|
||||
return reblog unless reblog.nil?
|
||||
|
||||
visibility = begin
|
||||
if reblogged_status.hidden?
|
||||
visibility = if reblogged_status.hidden?
|
||||
reblogged_status.visibility
|
||||
else
|
||||
options[:visibility] || account.user&.setting_default_privacy
|
||||
end
|
||||
end
|
||||
|
||||
reblog = account.statuses.create!(reblog: reblogged_status, text: '', visibility: visibility, rate_limit: options[:with_rate_limit])
|
||||
|
||||
|
|
|
@ -71,13 +71,11 @@ class ResolveAccountService < BaseService
|
|||
@username, @domain = uri.strip.gsub(/\A@/, '').split('@')
|
||||
end
|
||||
|
||||
@domain = begin
|
||||
if TagManager.instance.local_domain?(@domain)
|
||||
@domain = if TagManager.instance.local_domain?(@domain)
|
||||
nil
|
||||
else
|
||||
TagManager.instance.normalize_domain(@domain)
|
||||
end
|
||||
end
|
||||
|
||||
@uri = [@username, @domain].compact.join('@')
|
||||
end
|
||||
|
|
|
@ -4,13 +4,11 @@ class DomainValidator < ActiveModel::EachValidator
|
|||
def validate_each(record, attribute, value)
|
||||
return if value.blank?
|
||||
|
||||
domain = begin
|
||||
if options[:acct]
|
||||
domain = if options[:acct]
|
||||
value.split('@').last
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
record.errors.add(attribute, I18n.t('domain_validator.invalid_domain')) unless compliant?(domain)
|
||||
end
|
||||
|
|
|
@ -4,8 +4,7 @@ class ExistingUsernameValidator < ActiveModel::EachValidator
|
|||
def validate_each(record, attribute, value)
|
||||
return if value.blank?
|
||||
|
||||
usernames_and_domains = begin
|
||||
value.split(',').map do |str|
|
||||
usernames_and_domains = value.split(',').map do |str|
|
||||
username, domain = str.strip.gsub(/\A@/, '').split('@', 2)
|
||||
domain = nil if TagManager.instance.local_domain?(domain)
|
||||
|
||||
|
@ -13,7 +12,6 @@ class ExistingUsernameValidator < ActiveModel::EachValidator
|
|||
|
||||
[str, username, domain]
|
||||
end.compact
|
||||
end
|
||||
|
||||
usernames_with_no_accounts = usernames_and_domains.filter_map do |(str, username, domain)|
|
||||
str unless Account.find_remote(username, domain)
|
||||
|
|
|
@ -35,13 +35,11 @@ class ImportValidator < ActiveModel::Validator
|
|||
def validate_following_import(import, row_count)
|
||||
base_limit = FollowLimitValidator.limit_for_account(import.account)
|
||||
|
||||
limit = begin
|
||||
if import.overwrite?
|
||||
limit = if import.overwrite?
|
||||
base_limit
|
||||
else
|
||||
base_limit - import.account.following_count
|
||||
end
|
||||
end
|
||||
|
||||
import.errors.add(:data, I18n.t('users.follow_limit_reached', limit: base_limit)) if row_count > limit
|
||||
end
|
||||
|
|
|
@ -9,14 +9,12 @@ class BackupWorker
|
|||
backup_id = msg['args'].first
|
||||
|
||||
ActiveRecord::Base.connection_pool.with_connection do
|
||||
begin
|
||||
backup = Backup.find(backup_id)
|
||||
backup.destroy
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def perform(backup_id)
|
||||
backup = Backup.find(backup_id)
|
||||
|
|
|
@ -9,14 +9,12 @@ class PostProcessMediaWorker
|
|||
media_attachment_id = msg['args'].first
|
||||
|
||||
ActiveRecord::Base.connection_pool.with_connection do
|
||||
begin
|
||||
media_attachment = MediaAttachment.find(media_attachment_id)
|
||||
media_attachment.processing = :failed
|
||||
media_attachment.save
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
Sidekiq.logger.error("Processing media attachment #{media_attachment_id} failed with #{msg['error_message']}")
|
||||
end
|
||||
|
|
|
@ -19,13 +19,11 @@ class Scheduler::FollowRecommendationsScheduler
|
|||
fallback_recommendations = FollowRecommendation.order(rank: :desc).limit(SET_SIZE)
|
||||
|
||||
Trends.available_locales.each do |locale|
|
||||
recommendations = begin
|
||||
if AccountSummary.safe.filtered.localized(locale).exists? # We can skip the work if no accounts with that language exist
|
||||
recommendations = if AccountSummary.safe.filtered.localized(locale).exists? # We can skip the work if no accounts with that language exist
|
||||
FollowRecommendation.localized(locale).order(rank: :desc).limit(SET_SIZE).map { |recommendation| [recommendation.account_id, recommendation.rank] }
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
# Use language-agnostic results if there are not enough language-specific ones
|
||||
missing = SET_SIZE - recommendations.size
|
||||
|
|
|
@ -106,17 +106,14 @@ class FixAccountsUniqueIndex < ActiveRecord::Migration[5.2]
|
|||
# to check for (and skip past) uniqueness errors
|
||||
[Favourite, Follow, FollowRequest, Block, Mute].each do |klass|
|
||||
klass.where(account_id: duplicate_account.id).find_each do |record|
|
||||
begin
|
||||
record.update_attribute(:account_id, main_account.id)
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
next
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
[Follow, FollowRequest, Block, Mute].each do |klass|
|
||||
klass.where(target_account_id: duplicate_account.id).find_each do |record|
|
||||
begin
|
||||
record.update_attribute(:target_account_id, main_account.id)
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
next
|
||||
|
@ -124,4 +121,3 @@ class FixAccountsUniqueIndex < ActiveRecord::Migration[5.2]
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -43,7 +43,6 @@ class CopyStatusStats < ActiveRecord::Migration[5.2]
|
|||
# We cannot use bulk INSERT or overarching transactions here because of possible
|
||||
# uniqueness violations that we need to skip over
|
||||
Status.unscoped.select('id, reblogs_count, favourites_count, created_at, updated_at').find_each do |status|
|
||||
begin
|
||||
params = [[nil, status.id], [nil, status.reblogs_count], [nil, status.favourites_count], [nil, status.created_at], [nil, status.updated_at]]
|
||||
exec_insert('INSERT INTO status_stats (status_id, reblogs_count, favourites_count, created_at, updated_at) VALUES ($1, $2, $3, $4, $5)', nil, params)
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
|
@ -51,4 +50,3 @@ class CopyStatusStats < ActiveRecord::Migration[5.2]
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -43,7 +43,6 @@ class CopyAccountStats < ActiveRecord::Migration[5.2]
|
|||
# We cannot use bulk INSERT or overarching transactions here because of possible
|
||||
# uniqueness violations that we need to skip over
|
||||
Account.unscoped.select('id, statuses_count, following_count, followers_count, created_at, updated_at').find_each do |account|
|
||||
begin
|
||||
params = [[nil, account.id], [nil, account[:statuses_count]], [nil, account[:following_count]], [nil, account[:followers_count]], [nil, account.created_at], [nil, account.updated_at]]
|
||||
exec_insert('INSERT INTO account_stats (account_id, statuses_count, following_count, followers_count, created_at, updated_at) VALUES ($1, $2, $3, $4, $5, $6)', nil, params)
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
|
@ -51,4 +50,3 @@ class CopyAccountStats < ActiveRecord::Migration[5.2]
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -490,7 +490,6 @@ module Mastodon
|
|||
scope = Account.where(id: ::Follow.where(account: account).select(:target_account_id))
|
||||
|
||||
scope.find_each do |target_account|
|
||||
begin
|
||||
UnfollowService.new.call(account, target_account)
|
||||
rescue => e
|
||||
progress.log pastel.red("Error processing #{target_account.id}: #{e}")
|
||||
|
@ -498,7 +497,6 @@ module Mastodon
|
|||
progress.increment
|
||||
processed += 1
|
||||
end
|
||||
end
|
||||
|
||||
BootstrapTimelineWorker.perform_async(account.id)
|
||||
end
|
||||
|
@ -507,7 +505,6 @@ module Mastodon
|
|||
scope = Account.where(id: ::Follow.where(target_account: account).select(:account_id))
|
||||
|
||||
scope.find_each do |target_account|
|
||||
begin
|
||||
UnfollowService.new.call(target_account, account)
|
||||
rescue => e
|
||||
progress.log pastel.red("Error processing #{target_account.id}: #{e}")
|
||||
|
@ -516,7 +513,6 @@ module Mastodon
|
|||
processed += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
progress.finish
|
||||
say("Processed #{processed} relationships", :green, true)
|
||||
|
|
|
@ -42,7 +42,6 @@ module Mastodon
|
|||
|
||||
items.each do |item|
|
||||
futures << Concurrent::Future.execute(executor: pool) do
|
||||
begin
|
||||
if !progress.total.nil? && progress.progress + 1 > progress.total
|
||||
# The number of items has changed between start and now,
|
||||
# since there is no good way to predict the final count from
|
||||
|
@ -67,7 +66,6 @@ module Mastodon
|
|||
progress.increment
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
total.increment(items.size)
|
||||
futures.map(&:value)
|
||||
|
|
|
@ -79,13 +79,11 @@ module Mastodon
|
|||
skipped = 0
|
||||
|
||||
addresses.each do |address|
|
||||
ip_blocks = begin
|
||||
if options[:force]
|
||||
ip_blocks = if options[:force]
|
||||
IpBlock.where('ip >>= ?', address)
|
||||
else
|
||||
IpBlock.where('ip <<= ?', address)
|
||||
end
|
||||
end
|
||||
|
||||
if ip_blocks.empty?
|
||||
say("#{address} is not yet blocked", :yellow)
|
||||
|
|
|
@ -98,26 +98,22 @@ module Mastodon
|
|||
|
||||
owned_classes.each do |klass|
|
||||
klass.where(account_id: other_account.id).find_each do |record|
|
||||
begin
|
||||
record.update_attribute(:account_id, id)
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
next
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
target_classes = [Follow, FollowRequest, Block, Mute, AccountModerationNote, AccountPin]
|
||||
target_classes << AccountNote if ActiveRecord::Base.connection.table_exists?(:account_notes)
|
||||
|
||||
target_classes.each do |klass|
|
||||
klass.where(target_account_id: other_account.id).find_each do |record|
|
||||
begin
|
||||
record.update_attribute(:target_account_id, id)
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
next
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if ActiveRecord::Base.connection.table_exists?(:canonical_email_blocks)
|
||||
CanonicalEmailBlock.where(reference_account_id: other_account.id).find_each do |record|
|
||||
|
@ -601,14 +597,12 @@ module Mastodon
|
|||
owned_classes = [ConversationMute, AccountConversation]
|
||||
owned_classes.each do |klass|
|
||||
klass.where(conversation_id: duplicate_conv.id).find_each do |record|
|
||||
begin
|
||||
record.update_attribute(:account_id, main_conv.id)
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
next
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def merge_custom_emojis!(main_emoji, duplicate_emoji)
|
||||
owned_classes = [AnnouncementReaction]
|
||||
|
@ -629,50 +623,40 @@ module Mastodon
|
|||
owned_classes << Bookmark if ActiveRecord::Base.connection.table_exists?(:bookmarks)
|
||||
owned_classes.each do |klass|
|
||||
klass.where(status_id: duplicate_status.id).find_each do |record|
|
||||
begin
|
||||
record.update_attribute(:status_id, main_status.id)
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
next
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
StatusPin.where(account_id: main_status.account_id, status_id: duplicate_status.id).find_each do |record|
|
||||
begin
|
||||
record.update_attribute(:status_id, main_status.id)
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
next
|
||||
end
|
||||
end
|
||||
|
||||
Status.where(in_reply_to_id: duplicate_status.id).find_each do |record|
|
||||
begin
|
||||
record.update_attribute(:in_reply_to_id, main_status.id)
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
next
|
||||
end
|
||||
end
|
||||
|
||||
Status.where(reblog_of_id: duplicate_status.id).find_each do |record|
|
||||
begin
|
||||
record.update_attribute(:reblog_of_id, main_status.id)
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
next
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def merge_tags!(main_tag, duplicate_tag)
|
||||
[FeaturedTag].each do |klass|
|
||||
klass.where(tag_id: duplicate_tag.id).find_each do |record|
|
||||
begin
|
||||
record.update_attribute(:tag_id, main_tag.id)
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
next
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def find_duplicate_accounts
|
||||
ActiveRecord::Base.connection.select_all("SELECT string_agg(id::text, ',') AS ids FROM accounts GROUP BY lower(username), COALESCE(lower(domain), '') HAVING count(*) > 1")
|
||||
|
|
|
@ -116,14 +116,12 @@ module Mastodon
|
|||
|
||||
loop do
|
||||
objects = begin
|
||||
begin
|
||||
bucket.objects(start_after: last_key, prefix: prefix).limit(1000).map { |x| x }
|
||||
rescue => e
|
||||
progress.log(pastel.red("Error fetching list of files: #{e}"))
|
||||
progress.log("If you want to continue from this point, add --start-after=#{last_key} to your command") if last_key
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
break if objects.empty?
|
||||
|
||||
|
|
|
@ -43,13 +43,11 @@ module Mastodon
|
|||
exit(1)
|
||||
end
|
||||
|
||||
indices = begin
|
||||
if options[:only]
|
||||
indices = if options[:only]
|
||||
options[:only].map { |str| "#{str.camelize}Index".constantize }
|
||||
else
|
||||
INDICES
|
||||
end
|
||||
end
|
||||
|
||||
pool = Concurrent::FixedThreadPool.new(options[:concurrency], max_queue: options[:concurrency] * 10)
|
||||
importers = indices.index_with { |index| "Importer::#{index.name}Importer".constantize.new(batch_size: options[:batch_size], executor: pool) }
|
||||
|
|
|
@ -50,8 +50,7 @@ module Mastodon
|
|||
styles << :original unless styles.include?(:original)
|
||||
|
||||
styles.each do |style|
|
||||
success = begin
|
||||
case Paperclip::Attachment.default_options[:storage]
|
||||
success = case Paperclip::Attachment.default_options[:storage]
|
||||
when :s3
|
||||
upgrade_storage_s3(progress, attachment, style)
|
||||
when :fog
|
||||
|
@ -59,7 +58,6 @@ module Mastodon
|
|||
when :filesystem
|
||||
upgrade_storage_filesystem(progress, attachment, style)
|
||||
end
|
||||
end
|
||||
|
||||
upgraded = true if style == :original && success
|
||||
|
||||
|
|
|
@ -161,13 +161,11 @@ module Paperclip
|
|||
def lighten_or_darken(color, by)
|
||||
hue, saturation, light = rgb_to_hsl(color.r, color.g, color.b)
|
||||
|
||||
light = begin
|
||||
if light < 50
|
||||
light = if light < 50
|
||||
[100, light + by].min
|
||||
else
|
||||
[0, light - by].max
|
||||
end
|
||||
end
|
||||
|
||||
ColorDiff::Color::RGB.new(*hsl_to_rgb(hue, saturation, light))
|
||||
end
|
||||
|
|
|
@ -41,13 +41,11 @@ class Sanitize
|
|||
|
||||
current_node = env[:node]
|
||||
|
||||
scheme = begin
|
||||
if current_node['href'] =~ Sanitize::REGEX_PROTOCOL
|
||||
scheme = if current_node['href'] =~ Sanitize::REGEX_PROTOCOL
|
||||
Regexp.last_match(1).downcase
|
||||
else
|
||||
:relative
|
||||
end
|
||||
end
|
||||
|
||||
current_node.replace(Nokogiri::XML::Text.new(current_node.text, current_node.document)) unless LINK_PROTOCOLS.include?(scheme)
|
||||
end
|
||||
|
|
|
@ -4,7 +4,6 @@ namespace :db do
|
|||
namespace :migrate do
|
||||
desc 'Setup the db or migrate depending on state of db'
|
||||
task setup: :environment do
|
||||
begin
|
||||
if ActiveRecord::Migrator.current_version.zero?
|
||||
Rake::Task['db:migrate'].invoke
|
||||
Rake::Task['db:seed'].invoke
|
||||
|
@ -15,7 +14,6 @@ namespace :db do
|
|||
Rake::Task['db:migrate'].invoke
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
task :pre_migration_check do
|
||||
version = ActiveRecord::Base.connection.select_one("SELECT current_setting('server_version_num') AS v")['v'].to_i
|
||||
|
|
Loading…
Reference in a new issue