Skip to content

Improves model rows on model registry

Eduardo Bonet requested to merge model_registry/better_model_row into master

What does this MR do and why?

Adds pagination to model index

Limit was harcdoded to 100 entries, now it does proper pagination.

Changelog: added

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After
image image

How to set up and validate locally

  1. On rails console, enable the feature flag and create some data

    Feature.enable("model_registry")
    p = Project.find_by(id: 20) # or whatever project you want to use for testing
    3.times { |i|  Ml::FindOrCreateModelService.new(p, "model_#{i}").execute }
    
    Ml::FindOrCreateModelVersionService.new(p, { model_name: "model_1", version: "1.0.0" }).execute
    3.times { |i| Ml::FindOrCreateModelVersionService.new(p, { model_name: "model_2", version: "1.2.#{i}" }).execute }
  2. Open /-/ml/models on the selected project

Database

SELECT
    ml_models.*,
    count(ml_model_versions.id) AS version_count
FROM
    "ml_models"
    LEFT OUTER JOIN "ml_model_versions" ON "ml_model_versions"."model_id" = "ml_models"."id"
WHERE
    "ml_models"."project_id" = 19
GROUP BY
    "ml_models"."id"
ORDER BY
    "ml_models"."id" DESC
LIMIT 21

Local explain with data (5k+ model versions/models):

Limit  (cost=6.30..6.36 rows=3 width=48) (actual time=0.128..0.134 rows=3 loops=1)
  ->  GroupAggregate  (cost=6.30..6.36 rows=3 width=48) (actual time=0.127..0.132 rows=3 loops=1)
        Group Key: ml_models.id
        ->  Sort  (cost=6.30..6.31 rows=3 width=40) (actual time=0.116..0.118 rows=5 loops=1)
              Sort Key: ml_models.id DESC
              Sort Method: quicksort  Memory: 25kB
              ->  Nested Loop Left Join  (cost=0.56..6.28 rows=3 width=40) (actual time=0.065..0.079 rows=5 loops=1)
                    ->  Index Scan using index_ml_models_on_project_id on ml_models  (cost=0.28..2.35 rows=3 width=40) (actual time=0.051..0.053 rows=3 loops=1)
                          Index Cond: (project_id = 20)
                    ->  Index Only Scan using unique_ml_model_versions_on_model_id_and_id on ml_model_versions  (cost=0.28..1.30 rows=1 width=8) (actual time=0.005..0.006 rows=1 loops=3)
                          Index Cond: (model_id = ml_models.id)
                          Heap Fetches: 0
Planning Time: 1.715 ms
Execution Time: 0.391 ms

Execution result: https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/22941/commands/73971

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Eduardo Bonet

Merge request reports

Loading