Skip to content

Commit a908506

Browse files
committed
Avoid walking over entire load paths for simple precompile strings
1 parent 6ea7c60 commit a908506

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

lib/sprockets/rails/helper.rb

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,23 @@ def precompiled_assets
222222
@precompiled_assets ||= begin
223223
assets = Set.new
224224

225-
filters = (assets_precompile || []).map { |f|
226-
Sprockets::Manifest.compile_match_filter(f)
227-
}
228-
229-
env = assets_environment
230-
env.logical_paths do |logical_path, filename|
231-
if filters.any? { |f| f.call(logical_path, filename) }
232-
env.find_all_linked_assets(filename) do |asset|
233-
assets << asset
225+
paths, filters = (assets_precompile || []).flatten.partition { |arg| Sprockets::Manifest.simple_logical_path?(arg) }
226+
filters = filters.map { |arg| Sprockets::Manifest.compile_match_filter(arg) }
227+
228+
env = assets_environment.cached
229+
230+
paths.each do |path|
231+
env.find_all_linked_assets(path) do |asset|
232+
assets << asset
233+
end
234+
end
235+
236+
if filters.any?
237+
env.logical_paths do |logical_path, filename|
238+
if filters.any? { |f| f.call(logical_path, filename) }
239+
env.find_all_linked_assets(filename) do |asset|
240+
assets << asset
241+
end
234242
end
235243
end
236244
end

0 commit comments

Comments
 (0)