Skip to content

Commit

Permalink
improvement: make method more scalable
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobobq committed Dec 5, 2024
1 parent 5ec9070 commit 18f3437
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/resource_registry/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def fetch!(identifier)
).returns(T.nilable(Resource))
end
def fetch_for_repository(repository_class)
fetch_all.values.find { |r| r.repository_raw == repository_class.to_s }
resources_by_raw_repository[repository_class.to_s]
end

alias find_for_repository fetch_for_repository
Expand Down Expand Up @@ -78,6 +78,15 @@ def fetch_with_capabilities(*capabilities)
sig { returns(T::Hash[String, Resource]) }
attr_accessor :resources

sig { returns(T::Hash[String, Resource]) }
def resources_by_raw_repository
@resources_by_raw_repository ||=
T.let(
resources.values.index_by(&:repository_raw),
T.nilable(T::Hash[String, Resource])
)
end

sig { params(resources: T::Array[Resource]).returns(T::Boolean) }
def duplicated_identifier?(resources)
resources.map(&:identifier).uniq.size != resources.size
Expand Down

0 comments on commit 18f3437

Please sign in to comment.