Add search support for protected branches API
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.
db/migrate/20200131060031_add_name_index_on_protected_branches.rb
Migration Output of == 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%'
- Without index (before creating 1k protected branches for a specific project): https://explain.depesz.com/s/hQLg
- With index: (before creating 1k protected branches for a specific project) https://explain.depesz.com/s/BXoq
- With index (after creating 1k protected branches matching search for a specific project): https://explain.depesz.com/s/Pxpk
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry - [-] Documentation (if required)
-
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides - [-] Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. - [-] Tested in all supported browsers
- [-] Informed Infrastructure department of a default or new setting change, if applicable per definition of done
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
Edited by 🤖 GitLab Bot 🤖