Skip to content

Commit

Permalink
fix: improve fetch_for_repository performance by preventing reposit…
Browse files Browse the repository at this point in the history
…ory classes constantizing
  • Loading branch information
jacobobq committed Dec 5, 2024
1 parent 17696f5 commit 5ec9070
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
15 changes: 4 additions & 11 deletions lib/resource_registry/registry.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# typed: strict
# frozen_string_literal: true
# typed: false

require_relative "resource"
require_relative "capabilities/capability_config"
Expand Down Expand Up @@ -49,9 +49,11 @@ def fetch!(identifier)
).returns(T.nilable(Resource))
end
def fetch_for_repository(repository_class)
fetch_all.values.find { |r| r.repository == repository_class }
fetch_all.values.find { |r| r.repository_raw == repository_class.to_s }
end

alias find_for_repository fetch_for_repository

sig { returns(T::Hash[String, Resource]) }
def fetch_all
resources
Expand All @@ -71,15 +73,6 @@ def fetch_with_capabilities(*capabilities)
end
end

sig do
params(
repository: T::Class[ResourceRegistry::Repositories::Base[T.untyped]]
).returns(T.nilable(Resource))
end
def find_by_repository(repository)
fetch_all.values.find { |resource| resource.repository == repository }
end

private

sig { returns(T::Hash[String, Resource]) }
Expand Down
2 changes: 1 addition & 1 deletion lib/resource_registry/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def verbs_except(except)
def dump
{
"identifier" => identifier,
"repository" => repository.to_s,
"repository" => repository_raw,
"description" => description,
"relationships" => relationships.values.map(&:dump),
"capabilities" =>
Expand Down

0 comments on commit 5ec9070

Please sign in to comment.