Class: Gitlab::Graphql::Loaders::FullPathModelLoader
- Inherits:
-
Object
- Object
- Gitlab::Graphql::Loaders::FullPathModelLoader
- Defined in:
- lib/gitlab/graphql/loaders/full_path_model_loader.rb
Overview
Suitable for use to find resources that expose ‘where_full_path_in`, such as Project, Group, Namespace full path is always converted to lowercase for case-insensitive results
Instance Attribute Summary collapse
-
#full_path ⇒ Object
readonly
Returns the value of attribute full_path.
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
Instance Method Summary collapse
- #find ⇒ Object
-
#initialize(model_class, full_path) ⇒ FullPathModelLoader
constructor
A new instance of FullPathModelLoader.
Constructor Details
#initialize(model_class, full_path) ⇒ FullPathModelLoader
Returns a new instance of FullPathModelLoader.
12 13 14 15 |
# File 'lib/gitlab/graphql/loaders/full_path_model_loader.rb', line 12 def initialize(model_class, full_path) @model_class = model_class @full_path = full_path.downcase end |
Instance Attribute Details
#full_path ⇒ Object (readonly)
Returns the value of attribute full_path.
10 11 12 |
# File 'lib/gitlab/graphql/loaders/full_path_model_loader.rb', line 10 def full_path @full_path end |
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class.
10 11 12 |
# File 'lib/gitlab/graphql/loaders/full_path_model_loader.rb', line 10 def model_class @model_class end |
Instance Method Details
#find ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gitlab/graphql/loaders/full_path_model_loader.rb', line 17 def find BatchLoader::GraphQL.for(full_path).batch(key: model_class) do |full_paths, loader, args| scope = args[:key] # this logic cannot be placed in the NamespaceResolver due to N+1 scope = scope.without_project_namespaces if scope == Namespace # `with_route` avoids an N+1 calculating full_path scope = scope.where_full_path_in(full_paths).with_route .allow_cross_joins_across_databases(url: "https://gitlab.com/gitlab-org/gitlab/-/issues/420046") scope.each do |model_instance| loader.call(model_instance.full_path.downcase, model_instance) end end end |