Skip to content

Commit

Permalink
Merge branch 'main' into temp_for-ffxiv-mastodon
Browse files Browse the repository at this point in the history
  • Loading branch information
mayaeh committed Jul 13, 2023
2 parents 4ee168d + 8d0c695 commit 0cddb28
Show file tree
Hide file tree
Showing 467 changed files with 1,328 additions and 990 deletions.
60 changes: 5 additions & 55 deletions .haml-lint_todo.yml
Original file line number Diff line number Diff line change
@@ -1,73 +1,23 @@
# This configuration was generated by
# `haml-lint --auto-gen-config`
# on 2023-03-15 00:55:01 -0400 using Haml-Lint version 0.45.0.
# on 2023-07-11 23:58:05 +0200 using Haml-Lint version 0.48.0.
# The point is for the user to remove these configuration records
# one by one as the lints are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of Haml-Lint, may require this file to be generated again.

linters:
# Offense count: 63
# Offense count: 94
RuboCop:
exclude:
- 'app/views/accounts/_og.html.haml'
- 'app/views/admin/account_warnings/_account_warning.html.haml'
- 'app/views/admin/accounts/index.html.haml'
- 'app/views/admin/accounts/show.html.haml'
- 'app/views/admin/announcements/edit.html.haml'
- 'app/views/admin/announcements/new.html.haml'
- 'app/views/admin/disputes/appeals/_appeal.html.haml'
- 'app/views/admin/domain_blocks/edit.html.haml'
- 'app/views/admin/domain_blocks/new.html.haml'
- 'app/views/admin/ip_blocks/new.html.haml'
- 'app/views/admin/reports/actions/preview.html.haml'
- 'app/views/admin/reports/index.html.haml'
- 'app/views/admin/reports/show.html.haml'
- 'app/views/admin/roles/_form.html.haml'
- 'app/views/admin/settings/about/show.html.haml'
- 'app/views/admin/settings/appearance/show.html.haml'
- 'app/views/admin/settings/registrations/show.html.haml'
- 'app/views/admin/statuses/show.html.haml'
- 'app/views/auth/registrations/new.html.haml'
- 'app/views/disputes/strikes/show.html.haml'
- 'app/views/filters/_filter_fields.html.haml'
- 'app/views/invites/_form.html.haml'
- 'app/views/layouts/application.html.haml'
- 'app/views/layouts/error.html.haml'
- 'app/views/notification_mailer/_status.html.haml'
- 'app/views/settings/applications/_fields.html.haml'
- 'app/views/settings/imports/show.html.haml'
- 'app/views/settings/preferences/appearance/show.html.haml'
- 'app/views/settings/preferences/other/show.html.haml'
- 'app/views/statuses/_detailed_status.html.haml'
- 'app/views/statuses/_poll.html.haml'
- 'app/views/statuses/show.html.haml'
- 'app/views/statuses_cleanup/show.html.haml'
- 'app/views/user_mailer/warning.html.haml'
enabled: false

# Offense count: 913
# Offense count: 960
LineLength:
enabled: false

# Offense count: 22
UnnecessaryStringOutput:
exclude:
- 'app/views/accounts/show.html.haml'
- 'app/views/admin/custom_emojis/_custom_emoji.html.haml'
- 'app/views/admin/relays/_relay.html.haml'
- 'app/views/admin/rules/_rule.html.haml'
- 'app/views/admin/statuses/index.html.haml'
- 'app/views/auth/registrations/_sessions.html.haml'
- 'app/views/disputes/strikes/show.html.haml'
- 'app/views/notification_mailer/_status.html.haml'
- 'app/views/settings/two_factor_authentication_methods/index.html.haml'
- 'app/views/statuses/_detailed_status.html.haml'
- 'app/views/statuses/_poll.html.haml'
- 'app/views/statuses/_simple_status.html.haml'
- 'app/views/user_mailer/suspicious_sign_in.html.haml'
- 'app/views/user_mailer/webauthn_credential_added.html.haml'
- 'app/views/user_mailer/webauthn_credential_deleted.html.haml'
- 'app/views/user_mailer/welcome.html.haml'
enabled: false

# Offense count: 3
ViewLength:
Expand Down
6 changes: 5 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ AllCops:
Exclude:
- db/schema.rb
- 'bin/*'
- 'Rakefile'
- 'node_modules/**/*'
- 'Vagrantfile'
- 'vendor/**/*'
Expand Down Expand Up @@ -192,6 +191,11 @@ Style/RedundantBegin:
Style/RescueStandardError:
EnforcedStyle: implicit

# Reason: Simplify some spec layouts
# https://docs.rubocop.org/rubocop/cops_style.html#stylesemicolon
Style/Semicolon:
AllowAsExpressionSeparator: true

# Reason: Originally disabled for CodeClimate, and no config consensus has been found
# https://docs.rubocop.org/rubocop/cops_style.html#stylesymbolarray
Style/SymbolArray:
Expand Down
491 changes: 0 additions & 491 deletions .rubocop_todo.yml

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ GEM
sshkit (>= 1.9.0)
capistrano-bundler (2.1.0)
capistrano (~> 3.1)
capistrano-rails (1.6.2)
capistrano-rails (1.6.3)
capistrano (~> 3.1)
capistrano-bundler (>= 1.1, < 3)
capistrano-rbenv (2.2.0)
Expand Down Expand Up @@ -291,11 +291,11 @@ GEM
activesupport (>= 5.1)
haml (>= 4.0.6)
railties (>= 5.1)
haml_lint (0.45.0)
haml_lint (0.48.0)
haml (>= 4.0, < 6.2)
parallel (~> 1.10)
rainbow
rubocop (>= 0.50.0)
rubocop (>= 1.0)
sysexits (~> 1.1)
hashdiff (1.0.1)
hashie (5.0.0)
Expand Down Expand Up @@ -670,7 +670,7 @@ GEM
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
sshkit (1.21.4)
sshkit (1.21.5)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
stackprof (0.2.25)
Expand Down
4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)
require File.expand_path('config/application', __dir__)

Rails.application.load_tasks
2 changes: 1 addition & 1 deletion app/controllers/api/v1/bookmarks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def cached_bookmarks
end

def results
@_results ||= account_bookmarks.joins(:status).eager_load(:status).to_a_paginated_by_id(
@results ||= account_bookmarks.joins(:status).eager_load(:status).to_a_paginated_by_id(
limit_param(DEFAULT_STATUSES_LIMIT),
params_slice(:max_id, :since_id, :min_id)
)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/favourites_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def cached_favourites
end

def results
@_results ||= account_favourites.joins(:status).eager_load(:status).to_a_paginated_by_id(
@results ||= account_favourites.joins(:status).eager_load(:status).to_a_paginated_by_id(
limit_param(DEFAULT_STATUSES_LIMIT),
params_slice(:max_id, :since_id, :min_id)
)
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/api/v1/markers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ class Api::V1::MarkersController < Api::BaseController
before_action :require_user!

def index
@markers = current_user.markers.where(timeline: Array(params[:timeline])).index_by(&:timeline)
with_read_replica do
@markers = current_user.markers.where(timeline: Array(params[:timeline])).index_by(&:timeline)
end

render json: serialize_map(@markers)
end

Expand Down
8 changes: 6 additions & 2 deletions app/controllers/api/v1/notifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ class Api::V1::NotificationsController < Api::BaseController
DEFAULT_NOTIFICATIONS_LIMIT = 40

def index
@notifications = load_notifications
render json: @notifications, each_serializer: REST::NotificationSerializer, relationships: StatusRelationshipsPresenter.new(target_statuses_from_notifications, current_user&.account_id)
with_read_replica do
@notifications = load_notifications
@relationships = StatusRelationshipsPresenter.new(target_statuses_from_notifications, current_user&.account_id)
end

render json: @notifications, each_serializer: REST::NotificationSerializer, relationships: @relationships
end

def show
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/timelines/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Api::V1::Timelines::HomeController < Api::BaseController
after_action :insert_pagination_headers, unless: -> { @statuses.empty? }

def show
ApplicationRecord.connected_to(role: :read, prevent_writes: true) do
with_read_replica do
@statuses = load_statuses
@relationships = StatusRelationshipsPresenter.new(@statuses, current_user&.account_id)
end
Expand Down
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ApplicationController < ActionController::Base
include SessionTrackingConcern
include CacheConcern
include DomainControlHelper
include DatabaseHelper

helper_method :current_account
helper_method :current_session
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/auth/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def restart_session
redirect_to new_user_session_path, alert: I18n.t('devise.failure.timeout')
end

def set_attempt_session(user)
def register_attempt_in_session(user)
session[:attempt_user_id] = user.id
session[:attempt_user_updated_at] = user.updated_at.to_s
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/rate_limit_headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def api_throttle_data
end

def request_time
@_request_time ||= Time.now.utc
@request_time ||= Time.now.utc
end

def reset_period_offset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def authenticate_with_two_factor_via_otp(user)
end

def prompt_for_two_factor(user)
set_attempt_session(user)
register_attempt_in_session(user)

@body_classes = 'lighter'
@webauthn_enabled = user.webauthn_enabled?
Expand Down
11 changes: 11 additions & 0 deletions app/helpers/database_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module DatabaseHelper
def with_read_replica(&block)
ApplicationRecord.connected_to(role: :read, prevent_writes: true, &block)
end

def with_primary(&block)
ApplicationRecord.connected_to(role: :primary, &block)
end
end
2 changes: 1 addition & 1 deletion app/javascript/styles/mailer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ ul.rules-list {
padding-top: 0;
}

@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) and (orientation: landscape) {
@media only screen and (device-width >= 768px) and (device-width <= 1024px) and (orientation: landscape) {
body {
min-height: 1024px !important;
}
Expand Down
4 changes: 2 additions & 2 deletions app/lib/activitypub/activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ def first_local_follower
end

def follow_request_from_object
@follow_request ||= FollowRequest.find_by(target_account: @account, uri: object_uri) unless object_uri.nil?
@follow_request_from_object ||= FollowRequest.find_by(target_account: @account, uri: object_uri) unless object_uri.nil?
end

def follow_from_object
@follow ||= ::Follow.find_by(target_account: @account, uri: object_uri) unless object_uri.nil?
@follow_from_object ||= ::Follow.find_by(target_account: @account, uri: object_uri) unless object_uri.nil?
end

def fetch_remote_original_status
Expand Down
2 changes: 1 addition & 1 deletion app/lib/emoji_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def to_s
end
end

result << Nokogiri::XML::Text.new(text[last_index..-1], tree.document)
result << Nokogiri::XML::Text.new(text[last_index..], tree.document)
node.replace(result)
end

Expand Down
6 changes: 3 additions & 3 deletions app/lib/text_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def shortened_link(url, rel_me: false)

prefix = url.match(URL_PREFIX_REGEX).to_s
display_url = url[prefix.length, 30]
suffix = url[prefix.length + 30..-1]
cutoff = url[prefix.length..-1].length > 30
suffix = url[prefix.length + 30..]
cutoff = url[prefix.length..].length > 30

<<~HTML.squish.html_safe # rubocop:disable Rails/OutputSafety
<a href="#{h(url)}" target="_blank" rel="#{rel.join(' ')}" translate="no"><span class="invisible">#{h(prefix)}</span><span class="#{cutoff ? 'ellipsis' : ''}">#{h(display_url)}</span><span class="invisible">#{h(suffix)}</span></a>
Expand All @@ -84,7 +84,7 @@ def rewrite
indices.last
end

result << h(text[last_index..-1])
result << h(text[last_index..])

result
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/account_alias.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AccountAlias < ApplicationRecord

def acct=(val)
val = val.to_s.strip
super(val.start_with?('@') ? val[1..-1] : val)
super(val.start_with?('@') ? val[1..] : val)
end

def pretty_acct
Expand Down
2 changes: 1 addition & 1 deletion app/models/domain_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def rule_for(domain)

uri = Addressable::URI.new.tap { |u| u.host = domain.strip.delete('/') }
segments = uri.normalized_host.split('.')
variants = segments.map.with_index { |_, i| segments[i..-1].join('.') }
variants = segments.map.with_index { |_, i| segments[i..].join('.') }

where(domain: variants).order(Arel.sql('char_length(domain) desc')).first
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
Expand Down
2 changes: 1 addition & 1 deletion app/models/email_domain_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def domains_with_variants

segments = uri.normalized_host.split('.')

segments.map.with_index { |_, i| segments[i..-1].join('.') }
segments.map.with_index { |_, i| segments[i..].join('.') }
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/preview_card_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ def requires_review_notification?

def self.matching_domain(domain)
segments = domain.split('.')
where(domain: segments.map.with_index { |_, i| segments[i..-1].join('.') }).order(Arel.sql('char_length(domain) desc')).first
where(domain: segments.map.with_index { |_, i| segments[i..].join('.') }).order(Arel.sql('char_length(domain) desc')).first
end
end
24 changes: 18 additions & 6 deletions app/models/trends/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,10 @@ def to_ary
alias to_a to_ary

def to_arel
tmp_ids = ids

if tmp_ids.empty?
if ids_for_key.empty?
klass.none
else
scope = klass.joins("join unnest(array[#{tmp_ids.join(',')}]) with ordinality as x (id, ordering) on #{klass.table_name}.id = x.id").reorder('x.ordering')
scope = klass.joins(sanitized_join_sql).reorder('x.ordering')
scope = scope.offset(@offset) if @offset.present?
scope = scope.limit(@limit) if @limit.present?
scope
Expand All @@ -95,8 +93,22 @@ def load
self
end

def ids
redis.zrevrange(key, 0, -1).map(&:to_i)
def ids_for_key
@ids_for_key ||= redis.zrevrange(key, 0, -1).map(&:to_i)
end

def sanitized_join_sql
ActiveRecord::Base.sanitize_sql_array(join_sql_array)
end

def join_sql_array
[join_sql_query, ids_for_key]
end

def join_sql_query
<<~SQL.squish
JOIN unnest(array[?]) WITH ordinality AS x (id, ordering) ON #{klass.table_name}.id = x.id
SQL
end

def perform_queries
Expand Down
2 changes: 1 addition & 1 deletion app/services/resolve_url_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def fetched_resource
end

def fetch_resource_service
@_fetch_resource_service ||= FetchResourceService.new
@fetch_resource_service ||= FetchResourceService.new
end

def resource_url
Expand Down
2 changes: 1 addition & 1 deletion app/services/search_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def url_resource_results
end

def url_resource
@_url_resource ||= ResolveURLService.new.call(@query, on_behalf_of: @account)
@url_resource ||= ResolveURLService.new.call(@query, on_behalf_of: @account)
end

def url_resource_symbol
Expand Down
2 changes: 1 addition & 1 deletion app/validators/status_length_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def rewrite_entities(str, entities)
entity[:indices].last
end

result << str[last_index..-1]
result << str[last_index..]
result
end
end
Loading

0 comments on commit 0cddb28

Please sign in to comment.