Lazy load the repository reference only when needed
What does this MR do and why?
While working on this issue #524326 (closed) to connect WorkItems API to elasticsearch, I started getting the following error when searching for issues on the Project level:
RuntimeError (Project.workItems unexpectedly calls Gitaly!
Please either specify a constant complexity or add `calls_gitaly: true`
to the field declaration
):
lib/gitlab/error_tracking.rb:82:in `track_and_raise_for_dev_exception'
lib/gitlab/graphql/calls_gitaly/field_extension.rb:66:in `calls_gitaly_check'
lib/gitlab/graphql/calls_gitaly/field_extension.rb:20:in `after_resolve'
lib/gitlab/graphql/tracers/instrumentation_tracer.rb:23:in `execute_multiplex'
app/graphql/gitlab_schema.rb:44:in `multiplex'
app/controllers/graphql_controller.rb:253:in `execute_query'
app/controllers/graphql_controller.rb:65:in `execute'
app/controllers/glql/base_controller.rb:17:in `execute'
In the original implementation, the code computed the repository reference eagerly during initialization. That means it tries to load the repository reference (or the default branch) even when it's not needed, for example, in Work Item searches that don't use it.
With the suggested change, we are not going to compute the repository_ref until it's actually needed and the method is explicitly called.
References
How to set up and validate locally
I was testing it through local branch on my MR !185103 (merged). I used the following GLQL query to fetch the issues with the corresponding label from the current project (if you don't explicitly set the group in the GLQL query, it automatically takes the project where you are currently at):
```glql
display: table
fields: title, labels("workflow::*"), author, labels
query: label = "Brantforge"
```
You might need to enable both glql_integration and glql_work_items features to be able to test the code from my MR.