Skip to content

Use gitaly find_refs_by_oid instead of find all tags

In gitaly!3947 (merged), we added a new RPC FindRefsByOID. The purpose of this RPC is to, as the name suggests, find refs by passing in an object id and some other optional parameters.

Some context for the need of this RPC is here (by @stanhu) In gitlab-com/gl-infra/production#5662 (comment 697826180), we saw a lot of requests for `FindAllTags` that never completed. A project with JIRA enabled would attempt to call:
noteable.ref_names(project.repository).first

The FindAllTags triggered by ProcessCommitWorker comes from the JIRA integration. This happens when the commit message references a JIRA issue.

Stack trace
lib/gitlab/git/repository.rb:202:in `tags', 
lib/gitlab/git/repository.rb:513:in `refs_hash', 
lib/gitlab/git/commit.rb:439:in `refs', 
lib/gitlab/git/commit.rb:317:in `ref_names', 
app/models/commit.rb:343:in `method_missing', 
app/models/integrations/jira.rb:499:in `build_entity_meta', 
app/models/integrations/jira.rb:250:in `create_cross_reference_note', 
app/services/system_notes/issuables_service.rb:179:in `cross_reference', 
app/services/system_note_service.rb:217:in `cross_reference', 
app/models/concerns/mentionable.rb:150:in `block in create_cross_references!', 
app/models/concerns/mentionable.rb:149:in `each', 
app/models/concerns/mentionable.rb:149:in `create_cross_references!', 
app/workers/process_commit_worker.rb:50:in `process_commit_message', 
app/workers/process_commit_worker.rb:40:in `perform', 

In the JIRA payload, we want to include a ref name for the current commit so we do: noteable.ref_names(project.repository).first. But this method depends on Gitlab::Git::Repository#refs_hash, which fetches all tags and branches of the repository.

We probably need a new RPC to return N refs for a given OID.

Once #343034 (closed) is closed, we can swap out the call in app/models/integrations/jira.rb#build_entity_meta to noteable.ref_names to instead use find_refs_by_oid.