Add search by name to Image Repository
What does this MR do?
This MR adds the possibility to search by Image Repository name trough the project and group controllers it achieves so by:
- Add fuzzy search by name in the model
- Add search by name to the repositories_finder
- Pass down the name parameter from the controller to the finder
This MR was Co-authored-by
Index creation query ( used in the plan )
exec CREATE INDEX index_container_repository_on_name_trigram ON container_repositories USING GIN(name gin_trgm_ops);
Migration output
== 20200421092907 AddIndexContainerRepositoryOnNameTrigramToContainerRepository: migrating
-- transaction_open?()
-> 0.0000s
-- index_exists?(:container_repositories, :name, {:name=>"index_container_repository_on_name_trigram", :using=>:gin, :opclass=>{:name=>:gin_trgm_ops}, :algorithm=>:concurrently})
-> 0.0031s
-- execute("SET statement_timeout TO 0")
-> 0.0002s
-- add_index(:container_repositories, :name, {:name=>"index_container_repository_on_name_trigram", :using=>:gin, :opclass=>{:name=>:gin_trgm_ops}, :algorithm=>:concurrently})
-> 0.0192s
-- execute("RESET ALL")
-> 0.0002s
== 20200421092907 AddIndexContainerRepositoryOnNameTrigramToContainerRepository: migrated (0.0229s)
SQL Query
Raw from Rails console
ContainerRepository.search_by_name('foo').to_sql
=> "SELECT \"container_repositories\".* FROM \"container_repositories\" WHERE \"container_repositories\".\"name\" ILIKE '%foo%'"
Formatted
SELECT
container_repositories.*
FROM
container_repositories
WHERE
container_repositories.name ILIKE '%foo%'
Query Plan (OLD, pre Trigram Index)
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------
Seq Scan on container_repositories (cost=0.00..36593.05 rows=3036 width=39) (actual time=0.259..608.032 rows=3644 loops=1)
Filter: ((name)::text ~~* '%docker%'::text)
Rows Removed by Filter: 760256
Buffers: shared hit=6764
Planning time: 2.678 ms
Execution time: 608.393 ms
Query Plan
https://explain.depesz.com/s/LN9d
Summary
Time: 4.557 ms
- planning: 2.254 ms
- execution: 2.303 ms
- I/O read: 0.000 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 616 (~4.80 MiB) from the buffer pool
- reads: 0 from the OS file cache, including disk I/O
- dirtied: 6 (~48.00 KiB)
- writes: 0
Raw
Bitmap Heap Scan on public.container_repositories (cost=13.82..1909.21 rows=751 width=39) (actual time=0.263..2.188 rows=679 loops=1)
Buffers: shared hit=616 dirtied=6
-> Bitmap Index Scan using index_container_repository_on_name_trigram (cost=0.00..13.63 rows=751 width=0) (actual time=0.171..0.171 rows=679 loops=1)
Index Cond: ((container_repositories.name)::text ~~* '%foo%'::text)
Buffers: shared hit=4
Screenshots
No visual changes
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
Part of #214478 (closed)
Edited by Nicolò Maria Mezzopera