diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 89c5e1fe2e..ae3a189f4a 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,9 @@ +* Optimize load time for `Railtie#initialize_i18n`. Filter `I18n.load_path`s passed to the file watcher to only those + under `Rails.root`. Previously the watcher would grab all available locales, including those in gems + which do not require a watcher because they won't change. + + *Nick Schwaderer* + * Add a `filter` option to `in_order_of` to prioritize certain values in the sorting without filtering the results by these values. diff --git a/activesupport/lib/active_support/i18n_railtie.rb b/activesupport/lib/active_support/i18n_railtie.rb index 2b4075a39e..6d4eb11c4e 100644 --- a/activesupport/lib/active_support/i18n_railtie.rb +++ b/activesupport/lib/active_support/i18n_railtie.rb @@ -62,8 +62,9 @@ def self.initialize_i18n(app) if app.config.reloading_enabled? directories = watched_dirs_with_extensions(reloadable_paths) - reloader = app.config.file_watcher.new(I18n.load_path.dup, directories) do - I18n.load_path.keep_if { |p| File.exist?(p) } + root_load_paths = I18n.load_path.select { |path| path.start_with?(Rails.root.to_s) } + reloader = app.config.file_watcher.new(root_load_paths, directories) do + I18n.load_path.delete_if { |p| p.start_with?(Rails.root.to_s) && !File.exist?(p) } I18n.load_path |= reloadable_paths.flat_map(&:existent) end