Skip to content

Add search support for protected branches API

Patrick Bajao requested to merge 460-protected-branches-api-search into master

What does this MR do?

A new search param is added to support searching for protected branches by name.

This will be useful if user wants to look for a specific protected branch but there are lots of protected branches per page. This is needed in #460 (closed) as we're looking into using the protected branches API as source of dropdown data (discussion: !22749 (comment 277302197)).

This is inspired by how search on Projects API works. A gin index has been added to improve performance of ILIKE query.

Migration Output of db/migrate/20200131060031_add_name_index_on_protected_branches.rb

== 20200131060031 AddNameIndexOnProtectedBranches: migrating ==================
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:protected_branches, :name, {:name=>"index_protected_branches_on_name_trigram", :using=>:gin, :opclass=>{:name=>:gin_trgm_ops}, :algorithm=>:concurrently})
   -> 0.0041s
-- execute("SET statement_timeout TO 0")
   -> 0.0009s
-- add_index(:protected_branches, :name, {:name=>"index_protected_branches_on_name_trigram", :using=>:gin, :opclass=>{:name=>:gin_trgm_ops}, :algorithm=>:concurrently})
   -> 0.0274s
-- execute("RESET ALL")
   -> 0.0008s
== 20200131060031 AddNameIndexOnProtectedBranches: migrated (0.0338s) =========

Fuzzy Search Query Plan

Sample Query:

SELECT protected_branches.*
FROM protected_branches
WHERE protected_branches.project_id = 278964
AND protected_branches.name ILIKE '%stable%'

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team

#460 (closed)

Edited by 🤖 GitLab Bot 🤖

Merge request reports