Skip to content

Commit

Permalink
DEV: Upgrading Discourse to Zeitwerk (#8098)
Browse files Browse the repository at this point in the history
Zeitwerk simplifies working with dependencies in dev and makes it easier reloading class chains. 

We no longer need to use Rails "require_dependency" anywhere and instead can just use standard 
Ruby patterns to require files.

This is a far reaching change and we expect some followups here.
  • Loading branch information
lis2 authored and SamSaffron committed Oct 2, 2019
1 parent 68d35b1 commit 427d54b
Show file tree
Hide file tree
Showing 496 changed files with 292 additions and 1,049 deletions.
2 changes: 0 additions & 2 deletions app/controllers/about_controller.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_dependency 'rate_limiter'

class AboutController < ApplicationController

requires_login only: [:live_post_counts]
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/backups_controller.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require "backup_restore/backup_restore"
require "backup_restore"
require "backup_restore/backup_store"

class Admin::BackupsController < Admin::AdminController
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/admin/email_controller.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_dependency 'email/renderer'

class Admin::EmailController < Admin::AdminController

def index
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/admin/embedding_controller.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_dependency 'embedding'

class Admin::EmbeddingController < Admin::AdminController

before_action :fetch_embedding
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/admin/emojis_controller.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_dependency 'upload_creator'

class Admin::EmojisController < Admin::AdminController

def index
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/admin/reports_controller.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_dependency 'report'

class Admin::ReportsController < Admin::AdminController
def index
reports_methods = ['page_view_total_reqs'] +
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/admin/screened_ip_addresses_controller.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_dependency 'ip_addr'

class Admin::ScreenedIpAddressesController < Admin::AdminController

before_action :fetch_screened_ip_address, only: [:update, :destroy]
Expand Down
3 changes: 0 additions & 3 deletions app/controllers/admin/site_texts_controller.rb
@@ -1,8 +1,5 @@
# frozen_string_literal: true

require_dependency 'seed_data/categories'
require_dependency 'seed_data/topics'

class Admin::SiteTextsController < Admin::AdminController

def self.preferred_keys
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/admin/staff_action_logs_controller.rb
Expand Up @@ -26,8 +26,6 @@ def index
end

def diff
require_dependency "discourse_diff"

@history = UserHistory.find(params[:id])
prev = @history.previous_value
cur = @history.new_value
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/admin/themes_controller.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_dependency 'upload_creator'
require_dependency 'theme_store/tgz_exporter'
require 'base64'

class Admin::ThemesController < Admin::AdminController
Expand Down
4 changes: 0 additions & 4 deletions app/controllers/admin/users_controller.rb
@@ -1,9 +1,5 @@
# frozen_string_literal: true

require_dependency 'user_destroyer'
require_dependency 'admin_user_index_query'
require_dependency 'admin_confirmation'

class Admin::UsersController < Admin::AdminController

before_action :fetch_user, only: [:suspend,
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/admin/versions_controller.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_dependency 'discourse_updates'

class Admin::VersionsController < Admin::AdminController
def show
render json: DiscourseUpdates.check_version
Expand Down
14 changes: 0 additions & 14 deletions app/controllers/application_controller.rb
@@ -1,20 +1,6 @@
# frozen_string_literal: true

require 'current_user'
require_dependency 'canonical_url'
require_dependency 'discourse'
require_dependency 'custom_renderer'
require_dependency 'archetype'
require_dependency 'rate_limiter'
require_dependency 'crawler_detection'
require_dependency 'json_error'
require_dependency 'letter_avatar'
require_dependency 'distributed_cache'
require_dependency 'global_path'
require_dependency 'secure_session'
require_dependency 'topic_query'
require_dependency 'hijack'
require_dependency 'read_only_header'

class ApplicationController < ActionController::Base
include CurrentUser
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/categories_controller.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_dependency 'category_serializer'

class CategoriesController < ApplicationController

requires_login except: [:index, :categories_and_latest, :categories_and_top, :show, :redirect, :find_by_slug]
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/composer_controller.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_dependency 'html_to_markdown'

class ComposerController < ApplicationController

requires_login
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/composer_messages_controller.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_dependency 'composer_messages_finder'

class ComposerMessagesController < ApplicationController

requires_login
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/embed_controller.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_dependency 'topic_query_params'

class EmbedController < ApplicationController
include TopicQueryParams

Expand Down
2 changes: 0 additions & 2 deletions app/controllers/inline_onebox_controller.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_dependency 'inline_oneboxer'

class InlineOneboxController < ApplicationController
requires_login

Expand Down
2 changes: 0 additions & 2 deletions app/controllers/invites_controller.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_dependency 'rate_limiter'

class InvitesController < ApplicationController

requires_login only: [
Expand Down
3 changes: 0 additions & 3 deletions app/controllers/list_controller.rb
@@ -1,8 +1,5 @@
# frozen_string_literal: true

require_dependency 'topic_list_responder'
require_dependency 'topic_query_params'

class ListController < ApplicationController
include TopicListResponder
include TopicQueryParams
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/notifications_controller.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_dependency 'notification_serializer'

class NotificationsController < ApplicationController

requires_login
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/onebox_controller.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_dependency 'oneboxer'

class OneboxController < ApplicationController
requires_login

Expand Down
2 changes: 0 additions & 2 deletions app/controllers/post_action_users_controller.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_dependency 'discourse'

class PostActionUsersController < ApplicationController
def index
params.require(:post_action_type_id)
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/post_actions_controller.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_dependency 'discourse'

class PostActionsController < ApplicationController
requires_login

Expand Down
9 changes: 0 additions & 9 deletions app/controllers/posts_controller.rb
@@ -1,14 +1,5 @@
# frozen_string_literal: true

require_dependency 'new_post_manager'
require_dependency 'post_creator'
require_dependency 'post_action_destroyer'
require_dependency 'post_destroyer'
require_dependency 'post_merger'
require_dependency 'distributed_memoizer'
require_dependency 'new_post_result_serializer'
require_dependency 'post_locker'

class PostsController < ApplicationController

requires_login except: [
Expand Down
1 change: 0 additions & 1 deletion app/controllers/reviewables_controller.rb
@@ -1,5 +1,4 @@
# frozen_string_literal: true
require_dependency 'reviewable_explanation_serializer'

class ReviewablesController < ApplicationController
requires_login
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/search_controller.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_dependency 'search'

class SearchController < ApplicationController

skip_before_action :check_xhr, only: :show
Expand Down
6 changes: 0 additions & 6 deletions app/controllers/session_controller.rb
@@ -1,11 +1,5 @@
# frozen_string_literal: true

require_dependency 'rate_limiter'
require_dependency 'single_sign_on'
require_dependency 'single_sign_on_provider'
require_dependency 'url_helper'
require_dependency 'webauthn/webauthn'

class SessionController < ApplicationController
class LocalLoginNotAllowed < StandardError; end
rescue_from LocalLoginNotAllowed do
Expand Down
3 changes: 0 additions & 3 deletions app/controllers/similar_topics_controller.rb
@@ -1,8 +1,5 @@
# frozen_string_literal: true

require_dependency 'similar_topic_serializer'
require_dependency 'search/grouped_search_results'

class SimilarTopicsController < ApplicationController

class SimilarTopic
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/site_controller.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_dependency 'site_serializer'

class SiteController < ApplicationController
layout false
skip_before_action :preload_json, :check_xhr
Expand Down
3 changes: 0 additions & 3 deletions app/controllers/static_controller.rb
@@ -1,8 +1,5 @@
# frozen_string_literal: true

require_dependency 'distributed_memoizer'
require_dependency 'file_helper'

class StaticController < ApplicationController

skip_before_action :check_xhr, :redirect_to_login_if_required
Expand Down
4 changes: 0 additions & 4 deletions app/controllers/steps_controller.rb
@@ -1,9 +1,5 @@
# frozen_string_literal: true

require_dependency 'wizard'
require_dependency 'wizard/builder'
require_dependency 'wizard/step_updater'

class StepsController < ApplicationController
requires_login

Expand Down
5 changes: 0 additions & 5 deletions app/controllers/tags_controller.rb
@@ -1,10 +1,5 @@
# frozen_string_literal: true

require_dependency 'topic_list_responder'
require_dependency 'topic_query_params'
require_dependency 'topics_bulk_action'
require_dependency 'topic_query'

class TagsController < ::ApplicationController
include TopicListResponder
include TopicQueryParams
Expand Down
9 changes: 0 additions & 9 deletions app/controllers/topics_controller.rb
@@ -1,14 +1,5 @@
# frozen_string_literal: true

require_dependency 'topic_view'
require_dependency 'promotion'
require_dependency 'url_helper'
require_dependency 'topics_bulk_action'
require_dependency 'discourse_event'
require_dependency 'rate_limiter'
require_dependency 'topic_publisher'
require_dependency 'post_action_destroyer'

class TopicsController < ApplicationController
requires_login only: [
:timings,
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/uploads_controller.rb
@@ -1,8 +1,6 @@
# frozen_string_literal: true

require "mini_mime"
require_dependency 'upload_creator'
require_dependency "file_store/local_store"

class UploadsController < ApplicationController
requires_login except: [:show, :show_short]
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/user_avatars_controller.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_dependency 'letter_avatar'

class UserAvatarsController < ApplicationController

skip_before_action :preload_json, :redirect_to_login_if_required, :check_xhr, :verify_authenticity_token, only: [:show, :show_letter, :show_proxy_letter]
Expand Down
4 changes: 0 additions & 4 deletions app/controllers/users/omniauth_callbacks_controller.rb
@@ -1,10 +1,6 @@
# -*- encoding : utf-8 -*-
# frozen_string_literal: true

require_dependency 'email'
require_dependency 'enum'
require_dependency 'user_name_suggester'

class Users::OmniauthCallbacksController < ApplicationController

skip_before_action :redirect_to_login_if_required
Expand Down
8 changes: 0 additions & 8 deletions app/controllers/users_controller.rb
@@ -1,13 +1,5 @@
# frozen_string_literal: true

require_dependency 'discourse_hub'
require_dependency 'user_name_suggester'
require_dependency 'rate_limiter'
require_dependency 'wizard'
require_dependency 'wizard/builder'
require_dependency 'admin_confirmation'
require_dependency 'webauthn/webauthn'

class UsersController < ApplicationController

skip_before_action :authorize_mini_profiler, only: [:avatar]
Expand Down
4 changes: 0 additions & 4 deletions app/controllers/users_email_controller.rb
@@ -1,9 +1,5 @@
# frozen_string_literal: true

require_dependency 'rate_limiter'
require_dependency 'email_validator'
require_dependency 'email_updater'

class UsersEmailController < ApplicationController

requires_login only: [:index, :update]
Expand Down
3 changes: 0 additions & 3 deletions app/controllers/wizard_controller.rb
@@ -1,8 +1,5 @@
# frozen_string_literal: true

require_dependency 'wizard'
require_dependency 'wizard/builder'

class WizardController < ApplicationController
requires_login except: [:qunit]

Expand Down
8 changes: 0 additions & 8 deletions app/helpers/application_helper.rb
Expand Up @@ -2,14 +2,6 @@
# frozen_string_literal: true
require 'current_user'
require 'canonical_url'
require_dependency 'guardian'
require_dependency 'unread'
require_dependency 'age_words'
require_dependency 'configurable_urls'
require_dependency 'mobile_detection'
require_dependency 'category_badge'
require_dependency 'global_path'
require_dependency 'emoji'

module ApplicationHelper
include CurrentUser
Expand Down

3 comments on commit 427d54b

@discoursebot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/sidekiq-fails-to-start-after-upgrading-to-2-4-0-beta5/130031/8

@discoursebot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/topic-and-category-export-import/38930/41

@discoursereviewbot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.