Skip to content

Commit 97c5bfd

Browse files
committed
Switch to tracking files as they’re loaded
This avoids us having to iterate over the entire container.
1 parent 9fa2364 commit 97c5bfd

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

lib/dry/system/manifest_registrar.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,24 @@ class ManifestRegistrar
2222
def initialize(container)
2323
@container = container
2424
@config = container.config
25+
@loaded = Set.new
2526
end
2627

2728
# @api private
2829
def finalize!
29-
eager_loaded = container.keys.each_with_object(Set.new) do |key, set|
30-
set << Identifier.new(key).root_key
31-
end
32-
3330
::Dir[registrations_dir.join(RB_GLOB)].each do |file|
3431
ident = Identifier.new(File.basename(file, RB_EXT))
35-
call(ident) unless eager_loaded.include?(ident.root_key)
32+
33+
# Skip files already loaded during earlier stages of finalization, such as a provider
34+
# resolving a component satisfied via a manifest. Since `#call` uses `load`, re-running
35+
# here would duplicate registrations.
36+
call(ident) unless @loaded.include?(ident.root_key)
3637
end
3738
end
3839

3940
# @api private
4041
def call(component)
42+
@loaded << component.root_key
4143
load(root.join(config.registrations_dir, "#{component.root_key}#{RB_EXT}"))
4244
end
4345

0 commit comments

Comments
 (0)