Skip to content

Commit

Permalink
Only require the necessary Rails frameworks
Browse files Browse the repository at this point in the history
By requiring rails/all Solidus was loading a bunch of unnecessary code
taking more time and consuming more memory. This change allows apps
that want to cherry-pick Rails frameworks to benefit from the more
attentive choice.
  • Loading branch information
elia authored and filippoliverani committed Oct 16, 2020
1 parent ee05883 commit 1237e6a
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 3 deletions.
5 changes: 4 additions & 1 deletion backend/lib/spree/backend.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# frozen_string_literal: true

require 'rails/all'
require "active_record/railtie"
require "action_view/railtie"
require "sprockets/railtie"

require 'jquery-rails'
require 'coffee-rails'
require 'sassc-rails'
Expand Down
21 changes: 21 additions & 0 deletions backend/spec/lib/spree/backend_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require 'spec_helper'
require 'spree/backend'

RSpec.describe Spree::Backend do
it 'loads only the necessary Rails Frameworks' do
aggregate_failures do
expect(defined? ActionCable::Engine).to be_falsey
expect(defined? ActionController::Railtie).to be_truthy
expect(defined? ActionMailer::Railtie).to be_truthy
expect(defined? ActionView::Railtie).to be_truthy
expect(defined? ActiveJob::Railtie).to be_truthy
expect(defined? ActiveModel::Railtie).to be_truthy
expect(defined? ActiveRecord::Railtie).to be_truthy
expect(defined? ActiveStorage::Engine).to be_falsey
expect(defined? Rails::TestUnit::Railtie).to be_falsey
expect(defined? Sprockets::Railtie).to be_truthy
end
end
end
9 changes: 8 additions & 1 deletion core/lib/spree/core.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# frozen_string_literal: true

require 'rails/all'
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "sprockets/railtie"

require 'acts_as_list'
require 'awesome_nested_set'
require 'cancan'
Expand Down
1 change: 1 addition & 0 deletions core/lib/spree/testing_support/dummy_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'active_record/railtie'
require 'action_controller/railtie'
require 'action_mailer/railtie'
require 'active_storage/engine'

Rails.env = 'test'

Expand Down
21 changes: 21 additions & 0 deletions core/spec/lib/spree/core_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require 'spec_helper'
require 'spree/core'

RSpec.describe Spree::Core do
it 'loads only the necessary Rails Frameworks' do
aggregate_failures do
expect(defined? ActionCable::Engine).to be_falsey
expect(defined? ActionController::Railtie).to be_truthy
expect(defined? ActionMailer::Railtie).to be_truthy
expect(defined? ActionView::Railtie).to be_truthy
expect(defined? ActiveJob::Railtie).to be_truthy
expect(defined? ActiveModel::Railtie).to be_truthy
expect(defined? ActiveRecord::Railtie).to be_truthy
expect(defined? ActiveStorage::Engine).to be_truthy
expect(defined? Rails::TestUnit::Railtie).to be_falsey
expect(defined? Sprockets::Railtie).to be_truthy
end
end
end
6 changes: 5 additions & 1 deletion frontend/lib/spree/frontend.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# frozen_string_literal: true

require 'rails/all'
require "active_record/railtie"
require "action_controller/railtie"
require "action_view/railtie"
require "sprockets/railtie"

require 'jquery-rails'
require 'canonical-rails'
require 'sassc-rails'
Expand Down
21 changes: 21 additions & 0 deletions frontend/spec/lib/spree/frontend_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require 'spec_helper'
require 'spree/frontend'

RSpec.describe Spree::Frontend do
it 'loads only the necessary Rails Frameworks' do
aggregate_failures do
expect(defined? ActionCable::Engine).to be_falsey
expect(defined? ActionController::Railtie).to be_truthy
expect(defined? ActionMailer::Railtie).to be_truthy
expect(defined? ActionView::Railtie).to be_truthy
expect(defined? ActiveJob::Railtie).to be_truthy
expect(defined? ActiveModel::Railtie).to be_truthy
expect(defined? ActiveRecord::Railtie).to be_truthy
expect(defined? ActiveStorage::Engine).to be_falsey
expect(defined? Rails::TestUnit::Railtie).to be_falsey
expect(defined? Sprockets::Railtie).to be_truthy
end
end
end

0 comments on commit 1237e6a

Please sign in to comment.