Permalink
Browse files

Fix rubocop issues, introduce usage of frozen literal to improve perf…

…ormance
  • Loading branch information...
Gargron committed Nov 15, 2016
1 parent a91c3ef commit fdc17bea58f210f62ac0d9e836b68e84c6dbd15c
Showing with 329 additions and 126 deletions.
  1. +32 −4 .rubocop.yml
  2. +2 −0 Gemfile
  3. +2 −0 app/channels/application_cable/channel.rb
  4. +2 −0 app/channels/application_cable/connection.rb
  5. +2 −0 app/channels/hashtag_channel.rb
  6. +2 −0 app/channels/public_channel.rb
  7. +2 −0 app/channels/timeline_channel.rb
  8. +2 −0 app/controllers/about_controller.rb
  9. +3 −4 app/controllers/accounts_controller.rb
  10. +2 −0 app/controllers/api/salmon_controller.rb
  11. +2 −0 app/controllers/api/subscriptions_controller.rb
  12. +5 −3 app/controllers/api/v1/accounts_controller.rb
  13. +2 −0 app/controllers/api/v1/apps_controller.rb
  14. +2 −0 app/controllers/api/v1/follows_controller.rb
  15. +2 −0 app/controllers/api/v1/media_controller.rb
  16. +5 −3 app/controllers/api/v1/statuses_controller.rb
  17. +6 −4 app/controllers/api/v1/timelines_controller.rb
  18. +5 −3 app/controllers/api_controller.rb
  19. +2 −0 app/controllers/application_controller.rb
  20. +2 −0 app/controllers/auth/confirmations_controller.rb
  21. +2 −0 app/controllers/auth/passwords_controller.rb
  22. +2 −0 app/controllers/auth/registrations_controller.rb
  23. +2 −0 app/controllers/auth/sessions_controller.rb
  24. +2 −0 app/controllers/home_controller.rb
  25. +2 −0 app/controllers/media_controller.rb
  26. +2 −0 app/controllers/oauth/authorizations_controller.rb
  27. +2 −0 app/controllers/settings/preferences_controller.rb
  28. +2 −0 app/controllers/settings/profiles_controller.rb
  29. +3 −3 app/controllers/stream_entries_controller.rb
  30. +2 −0 app/controllers/tags_controller.rb
  31. +6 −4 app/controllers/xrd_controller.rb
  32. +2 −0 app/helpers/about_helper.rb
  33. +5 −3 app/helpers/accounts_helper.rb
  34. +2 −0 app/helpers/application_helper.rb
  35. +8 −2 app/helpers/atom_builder_helper.rb
  36. +3 −1 app/helpers/home_helper.rb
  37. +2 −0 app/helpers/routing_helper.rb
  38. +2 −0 app/helpers/stream_entries_helper.rb
  39. +2 −0 app/helpers/tags_helper.rb
  40. +2 −0 app/helpers/xrd_helper.rb
  41. +15 −13 app/lib/feed_manager.rb
  42. +4 −2 app/lib/formatter.rb
  43. +3 −1 app/lib/tag_manager.rb
  44. +2 −0 app/mailers/application_mailer.rb
  45. +2 −0 app/mailers/notification_mailer.rb
  46. +6 −4 app/models/account.rb
  47. +2 −0 app/models/application_record.rb
  48. +2 −0 app/models/block.rb
  49. +2 −0 app/models/concerns/paginable.rb
  50. +2 −0 app/models/concerns/streamable.rb
  51. +2 −0 app/models/concerns/targetable.rb
  52. +2 −0 app/models/domain_block.rb
  53. +2 −0 app/models/favourite.rb
  54. +3 −1 app/models/feed.rb
  55. +2 −0 app/models/follow.rb
  56. +2 −0 app/models/follow_suggestion.rb
  57. +12 −10 app/models/media_attachment.rb
  58. +2 −0 app/models/mention.rb
  59. +6 −9 app/models/status.rb
  60. +7 −1 app/models/stream_entry.rb
  61. +2 −0 app/models/tag.rb
  62. +2 −0 app/models/user.rb
  63. +2 −0 app/services/base_service.rb
  64. +2 −0 app/services/block_domain_service.rb
  65. +3 −1 app/services/block_service.rb
  66. +2 −0 app/services/fan_out_on_write_service.rb
  67. +2 −0 app/services/favourite_service.rb
  68. +8 −12 app/services/fetch_atom_service.rb
  69. +4 −2 app/services/fetch_remote_account_service.rb
  70. +5 −3 app/services/fetch_remote_status_service.rb
  71. +4 −2 app/services/follow_remote_account_service.rb
  72. +3 −1 app/services/follow_service.rb
  73. +2 −0 app/services/post_status_service.rb
  74. +3 −3 app/services/precompute_feed_service.rb
  75. +7 −5 app/services/process_feed_service.rb
  76. +3 −3 app/services/process_hashtags_service.rb
  77. +4 −4 app/services/process_interaction_service.rb
  78. +2 −0 app/services/process_mentions_service.rb
  79. +2 −0 app/services/reblog_service.rb
  80. +3 −1 app/services/remove_status_service.rb
  81. +6 −4 app/services/search_service.rb
  82. +2 −0 app/services/send_interaction_service.rb
  83. +2 −0 app/services/subscribe_service.rb
  84. +2 −0 app/services/unblock_service.rb
  85. +2 −0 app/services/unfavourite_service.rb
  86. +3 −1 app/services/unfollow_service.rb
  87. +7 −5 app/services/update_remote_profile_service.rb
  88. +2 −0 app/workers/distribution_worker.rb
  89. +2 −0 app/workers/hub_ping_worker.rb
  90. +2 −0 app/workers/notification_worker.rb
  91. +2 −0 app/workers/processing_worker.rb
  92. +2 −0 app/workers/regeneration_worker.rb
  93. +2 −0 app/workers/thread_resolve_worker.rb
  94. +1 −0 config.ru
  95. +4 −2 config/initializers/redis.rb
  96. +4 −2 lib/tasks/mastodon.rake
@@ -18,9 +18,29 @@ Metrics/MethodLength:
CountComments: false
Max: 10
Metrics/ModuleLength:
Metrics/AbcSize:
Max: 100
Metrics/BlockNesting:
Max: 3
Metrics/ClassLength:
CountComments: false
Max: 200
Metrics/CyclomaticComplexity:
Max: 15
Metrics/MethodLength:
Max: 55
Metrics/ModuleLength:
CountComments: false
Max: 200
Metrics/PerceivedComplexity:
Max: 10
Metrics/ParameterLists:
Max: 4
CountKeywordArgs: true
@@ -37,10 +57,10 @@ Style/Documentation:
Enabled: false
Style/DoubleNegation:
Enabled: false
Enabled: true
Style/FrozenStringLiteralComment:
Enabled: false
Enabled: true
Style/SpaceInsideHashLiteralBraces:
EnforcedStyle: space
@@ -51,10 +71,18 @@ Style/TrailingCommaInLiteral:
Style/RegexpLiteral:
Enabled: false
Style/Lambda:
Enabled: false
Rails/HasAndBelongsToMany:
Enabled: false
AllCops:
TargetRubyVersion: 2.2
TargetRubyVersion: 2.3
Exclude:
- 'spec/**/*'
- 'db/**/*'
- 'app/views/**/*'
- 'config/**/*'
- 'bin/*'
- 'Rakefile'
@@ -1,3 +1,5 @@
# frozen_string_literal: true
source 'https://rubygems.org'
gem 'rails', '5.0.0.1'
@@ -1,3 +1,5 @@
# frozen_string_literal: true
module ApplicationCable
class Channel < ActionCable::Channel::Base
protected
@@ -1,3 +1,5 @@
# frozen_string_literal: true
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class HashtagChannel < ApplicationCable::Channel
def subscribed
tag = params[:tag].downcase
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class PublicChannel < ApplicationCable::Channel
def subscribed
stream_from 'timeline:public', lambda { |encoded_message|
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class TimelineChannel < ApplicationCable::Channel
def subscribed
stream_from "timeline:#{current_user.account_id}"
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class AboutController < ApplicationController
before_action :set_body_classes
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class AccountsController < ApplicationController
layout 'public'
@@ -41,10 +43,7 @@ def set_account
end
def set_link_headers
response.headers['Link'] = LinkHeader.new([
[webfinger_account_url, [['rel', 'lrdd'], ['type', 'application/xrd+xml']]],
[account_url(@account, format: 'atom'), [['rel', 'alternate'], ['type', 'application/atom+xml']]]
])
response.headers['Link'] = LinkHeader.new([[webfinger_account_url, [%w(rel lrdd), %w(type application/xrd+xml)]], [account_url(@account, format: 'atom'), [%w(rel alternate), %w(type application/atom+xml)]]])
end
def webfinger_account_url
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Api::SalmonController < ApiController
before_action :set_account
respond_to :txt
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Api::SubscriptionsController < ApiController
before_action :set_account
respond_to :txt
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Api::V1::AccountsController < ApiController
before_action -> { doorkeeper_authorize! :read }, except: [:follow, :unfollow, :block, :unblock]
before_action -> { doorkeeper_authorize! :follow }, only: [:follow, :unfollow, :block, :unblock]
@@ -20,7 +22,7 @@ def following
@accounts = results.map { |f| accounts[f.target_account_id] }
next_path = following_api_v1_account_url(max_id: results.last.id) if results.size == DEFAULT_ACCOUNTS_LIMIT
prev_path = following_api_v1_account_url(since_id: results.first.id) if results.size > 0
prev_path = following_api_v1_account_url(since_id: results.first.id) unless results.empty?
set_pagination_headers(next_path, prev_path)
@@ -33,7 +35,7 @@ def followers
@accounts = results.map { |f| accounts[f.account_id] }
next_path = followers_api_v1_account_url(max_id: results.last.id) if results.size == DEFAULT_ACCOUNTS_LIMIT
prev_path = followers_api_v1_account_url(since_id: results.first.id) if results.size > 0
prev_path = followers_api_v1_account_url(since_id: results.first.id) unless results.empty?
set_pagination_headers(next_path, prev_path)
@@ -56,7 +58,7 @@ def statuses
set_maps(@statuses)
next_path = statuses_api_v1_account_url(max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
prev_path = statuses_api_v1_account_url(since_id: @statuses.first.id) if @statuses.size > 0
prev_path = statuses_api_v1_account_url(since_id: @statuses.first.id) unless @statuses.empty?
set_pagination_headers(next_path, prev_path)
end
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Api::V1::AppsController < ApiController
respond_to :json
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Api::V1::FollowsController < ApiController
before_action -> { doorkeeper_authorize! :follow }
before_action :require_user!
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Api::V1::MediaController < ApiController
before_action -> { doorkeeper_authorize! :write }
before_action :require_user!
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Api::V1::StatusesController < ApiController
before_action -> { doorkeeper_authorize! :read }, except: [:create, :destroy, :reblog, :unreblog, :favourite, :unfavourite]
before_action -> { doorkeeper_authorize! :write }, only: [:create, :destroy, :reblog, :unreblog, :favourite, :unfavourite]
@@ -10,7 +12,7 @@ def show
end
def context
@context = OpenStruct.new({ ancestors: @status.ancestors, descendants: @status.descendants })
@context = OpenStruct.new(ancestors: @status.ancestors, descendants: @status.descendants)
set_maps([@status] + @context[:ancestors] + @context[:descendants])
end
@@ -20,7 +22,7 @@ def reblogged_by
@accounts = results.map { |r| accounts[r.account_id] }
next_path = reblogged_by_api_v1_status_url(max_id: results.last.id) if results.size == DEFAULT_ACCOUNTS_LIMIT
prev_path = reblogged_by_api_v1_status_url(since_id: results.first.id) if results.size > 0
prev_path = reblogged_by_api_v1_status_url(since_id: results.first.id) unless results.empty?
set_pagination_headers(next_path, prev_path)
@@ -33,7 +35,7 @@ def favourited_by
@accounts = results.map { |f| accounts[f.account_id] }
next_path = favourited_by_api_v1_status_url(max_id: results.last.id) if results.size == DEFAULT_ACCOUNTS_LIMIT
prev_path = favourited_by_api_v1_status_url(since_id: results.first.id) if results.size > 0
prev_path = favourited_by_api_v1_status_url(since_id: results.first.id) unless results.empty?
set_pagination_headers(next_path, prev_path)
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Api::V1::TimelinesController < ApiController
before_action -> { doorkeeper_authorize! :read }
before_action :require_user!, only: [:home, :mentions]
@@ -10,7 +12,7 @@ def home
set_maps(@statuses)
next_path = api_v1_home_timeline_url(max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
prev_path = api_v1_home_timeline_url(since_id: @statuses.first.id) if @statuses.size > 0
prev_path = api_v1_home_timeline_url(since_id: @statuses.first.id) unless @statuses.empty?
set_pagination_headers(next_path, prev_path)
@@ -23,7 +25,7 @@ def mentions
set_maps(@statuses)
next_path = api_v1_mentions_timeline_url(max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
prev_path = api_v1_mentions_timeline_url(since_id: @statuses.first.id) if @statuses.size > 0
prev_path = api_v1_mentions_timeline_url(since_id: @statuses.first.id) unless @statuses.empty?
set_pagination_headers(next_path, prev_path)
@@ -36,7 +38,7 @@ def public
set_maps(@statuses)
next_path = api_v1_public_timeline_url(max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
prev_path = api_v1_public_timeline_url(since_id: @statuses.first.id) if @statuses.size > 0
prev_path = api_v1_public_timeline_url(since_id: @statuses.first.id) unless @statuses.empty?
set_pagination_headers(next_path, prev_path)
@@ -50,7 +52,7 @@ def tag
set_maps(@statuses)
next_path = api_v1_hashtag_timeline_url(params[:id], max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
prev_path = api_v1_hashtag_timeline_url(params[:id], since_id: @statuses.first.id) if @statuses.size > 0
prev_path = api_v1_hashtag_timeline_url(params[:id], since_id: @statuses.first.id) unless @statuses.empty?
set_pagination_headers(next_path, prev_path)
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class ApiController < ApplicationController
DEFAULT_STATUSES_LIMIT = 20
DEFAULT_ACCOUNTS_LIMIT = 40
@@ -51,8 +53,8 @@ def set_rate_limit_headers
def set_pagination_headers(next_path = nil, prev_path = nil)
links = []
links << [next_path, [['rel', 'next']]] if next_path
links << [prev_path, [['rel', 'prev']]] if prev_path
links << [next_path, [%w(rel next)]] if next_path
links << [prev_path, [%w(rel prev)]] if prev_path
response.headers['Link'] = LinkHeader.new(links)
end
@@ -76,7 +78,7 @@ def render_empty
render json: {}, status: 200
end
def set_maps(statuses)
def set_maps(statuses) # rubocop:disable Style/AccessorMethodName
if current_account.nil?
@reblogs_map = {}
@favourites_map = {}
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Auth::ConfirmationsController < Devise::ConfirmationsController
layout 'auth'
end
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Auth::PasswordsController < Devise::PasswordsController
layout 'auth'
end
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Auth::RegistrationsController < Devise::RegistrationsController
layout 'auth'
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Auth::SessionsController < Devise::SessionsController
include Devise::Controllers::Rememberable
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class HomeController < ApplicationController
before_action :authenticate_user!
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class MediaController < ApplicationController
before_action :set_media_attachment
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Oauth::AuthorizationsController < Doorkeeper::AuthorizationsController
skip_before_action :authenticate_resource_owner!
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Settings::PreferencesController < ApplicationController
layout 'auth'
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Settings::ProfilesController < ApplicationController
layout 'auth'
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class StreamEntriesController < ApplicationController
layout 'public'
@@ -29,9 +31,7 @@ def set_account
end
def set_link_headers
response.headers['Link'] = LinkHeader.new([
[account_stream_entry_url(@account, @stream_entry, format: 'atom'), [['rel', 'alternate'], ['type', 'application/atom+xml']]]
])
response.headers['Link'] = LinkHeader.new([[account_stream_entry_url(@account, @stream_entry, format: 'atom'), [%w(rel alternate), %w(type application/atom+xml)]]])
end
def set_stream_entry
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class TagsController < ApplicationController
layout 'public'
Oops, something went wrong.

0 comments on commit fdc17be

Please sign in to comment.