Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

don't eagerload paths that have been flagged as eager_load => false #8146

Closed
wants to merge 1 commit into from

6 participants

@crankharder

Hey @spastorino,

This has created a regression in how paths are eager loaded:

53778ec

However, I don't think there's anything wrong with this commit.... I'll explain more:

Before the above commit:

?> pp Rails.configuration.paths.eager_load
["/home/jsharpe/project/app/assets",
"/home/jsharpe/project/app/controllers",
"/home/jsharpe/project/app/helpers",
"/home/jsharpe/project/app/models",
"/home/jsharpe/project/app/modules",
"/home/jsharpe/project/app/structs",
"/home/jsharpe/project/app/workers"]

After the commit:

?> pp Rails.configuration.paths.eager_load
["/home/jsharpe/project/app/controllers",
"/home/jsharpe/project/app/helpers",
"/home/jsharpe/project/app/models",
"/home/jsharpe/project/app/modules",
"/home/jsharpe/project/app/structs",
"/home/jsharpe/project/app/workers",
"/home/jsharpe/project/app"]

Note that /assets is now missing from #eager_load - which was the intent of the patch. However, /app is now included when it wasn't before.

I'm pretty sure that it was a bug before the commit that /app was missing. It is set to be eager_load => true here:

https://github.com/rails/rails/blob/3-2-rel/railties/lib/rails/engine/configuration.rb#L42

Now that /app is (correctly) part of eager_load, it now automatically loads anything inside of /app - including things that are specifically intended not be loaded.

For example, if I do this in config/ application.rb:

config.paths.add('app/manifests', :eager_load => false)

then files located in app/manifests are loaded - and that I believe is a regression. The attached patch fixes that.

I'm trying to set up the rails test suite up and running, but I wanted to at least start this conversation.

Thanks!

@rafaelfranca rafaelfranca commented on the diff
railties/lib/rails/engine.rb
@@ -436,7 +436,7 @@ def eager_load!
config.eager_load_paths.each do |load_path|
matcher = /\A#{Regexp.escape(load_path)}\/(.*)\.rb\Z/
Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
- require_dependency file.sub(matcher, '\1')
+ require_dependency file.sub(matcher, '\1') unless config.paths.skip_eager_load.any?{|path| file.match(path)}
@rafaelfranca Owner

If we need to exclude something we need to fix filter_by, this is not the proper place

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@rafaelfranca
Owner

Yes. I agree that this is wrong. We need to fix it first on master and backport to 3-2-stable.

@josevalim
Owner

Thanks. However, I don't think the solution is proper. The question we need to answer is, why is app appearing on eager_load paths and make it no longer appear in there.

@spastorino spastorino closed this pull request from a commit
@spastorino spastorino Revert "Respect children paths filter settings"
This reverts commit 53778ec.
Closes #8146
fc5ccd2
@spastorino spastorino closed this in fc5ccd2
@spastorino spastorino referenced this pull request from a commit
@spastorino spastorino Revert "Respect children paths filter settings"
This reverts commit 53778ec.
Closes #8146
054578a
@spastorino spastorino reopened this
@rafaelfranca
Owner

@spastorino thank you

@spastorino
Owner

This needs to be fixed in master, unsure if I would change this in 3-2-stable

@fgrehm

Hey all,

Just for the record, ran into an issue when trying to setup activeadmin on a new app using 3.2.9.rc2 that might be related to this as it seems to be fixed with rc3.

I was going to create an issue over there and ended up creating this repo to showcase the bug. Now that I found out that the problem was probably not activeadmin I thought that you guys might be interested ;-)

Steps to reproduce:

$ git clone git://github.com/fgrehm/active_admin-issue.git
$ cd active_admin-issue
$ git checkout 781793c
$ bundle
$ rake db:migrate
  # Expected active_admin-issue/app/admin/admin_user.rb to define Admin::AdminUser 

The rails-3.2.9.rc3 branch have the changes I made on the master branch to make the gem work with rc2 reverted and works like a charm.

Cheers!

/cc @gregbell

@nikitug nikitug referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@rafaelfranca rafaelfranca referenced this pull request from a commit
@rafaelfranca rafaelfranca Revert "Merge pull request #7587 from elia/fix-too-eager-loading"
This reverts commit 3663057.

REASON: This caused a regression that add app folder in the eager load
path. See #8146 for more information.

Conflicts:
	railties/CHANGELOG.md
7f96e43
@rafaelfranca

Related with #7587

@rafaelfranca rafaelfranca was assigned
@arthurnn
Collaborator

@rafaelfranca Should we close this, and if the behaviour is still incorrect open a new PR against master?

@rafaelfranca
Owner

@arthurnn right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 1 deletion.
  1. +1 −1  railties/lib/rails/engine.rb
  2. +4 −0 railties/lib/rails/paths.rb
View
2  railties/lib/rails/engine.rb
@@ -436,7 +436,7 @@ def eager_load!
config.eager_load_paths.each do |load_path|
matcher = /\A#{Regexp.escape(load_path)}\/(.*)\.rb\Z/
Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
- require_dependency file.sub(matcher, '\1')
+ require_dependency file.sub(matcher, '\1') unless config.paths.skip_eager_load.any?{|path| file.match(path)}
@rafaelfranca Owner

If we need to exclude something we need to fix filter_by, this is not the proper place

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
end
end
end
View
4 railties/lib/rails/paths.rb
@@ -72,6 +72,10 @@ def autoload_once
filter_by(:autoload_once?)
end
+ def skip_eager_load
+ @skip_eager_load ||= all_paths.select{|path| !path.eager_load?}.flatten
+ end
+
def eager_load
filter_by(:eager_load?)
end
Something went wrong with that request. Please try again.