Skip to content

Implements sort for a CI Catalog Resource

Laura Montemayor requested to merge add-sort-to-ci-catalog into master

What does this MR do and why?

Implements sorting by name for a CI Catalog Resource.

How to reproduce

To test this, you must have the :ci_namespace_catalog_experimental feature flag enabled.

1. Create three + projects with a README.md and a description.

2. Make the projects a Catalog Resource.

You can do this through the rails console or a graphql mutation:

mutation {
    catalogResourcesCreate(input: { projectPath: "path-to-project"}) {
      errors
  }
}

Note: The resolver uses the namespace of the projectPath so the results are all associated with it.

3. Query with different parameters

Query, no sort parameter:

{
  ciCatalogResources(projectPath: "root/simple-project"){
  	nodes{
      name
    }
  }
}

Response, sorted by default, which is descending created date:

{
  "data": {
    "ciCatalogResources": {
      "nodes": [
        {
          "name": "simple-project"
        },
        {
          "name": "Middle"
        },
        {
          "name": "ci-components"
        }
      ]
    }
  }
}

Query, with NAME_ASC sort parameter:

{
  ciCatalogResources(projectPath: "root/simple-project", sort: NAME_ASC){
  	nodes{
      name
    }
  }
}

Response:

{
  "data": {
    "ciCatalogResources": {
      "nodes": [
        {
          "name": "ci-components"
        },
        {
          "name": "simple-project"
        },
        {
          "name": "z-components"
        }
      ]
    }
  }
}

Query, with NAME_DESC sort parameter:

{
  ciCatalogResources(projectPath: "root/simple-project", sort: NAME_DESC){
  	nodes{
      name
    }
  }
}

Response:

{
  "data": {
    "ciCatalogResources": {
      "nodes": [
        {
          "name": "z-components"
        },
        {
          "name": "simple-project"
        },
        {
          "name": "ci-components"
        }
      ]
    }
  }
}

Query plans

SELECT "catalog_resources".* FROM "catalog_resources" ORDER BY "catalog_resources"."created_at" DESC
Looks good

Statistics:

Time: 0.608 ms
  - planning: 0.523 ms
  - execution: 0.085 ms
    - I/O read: 0.000 ms
    - I/O write: 0.000 ms

Shared buffers:
  - hits: 3 (~24.00 KiB) from the buffer pool
  - reads: 0 from the OS file cache, including disk I/O
  - dirtied: 0
  - writes: 0

scope :order_by_name_desc, -> { joins(:project).merge(Project.sorted_by_name_desc) }

Statistics:

  
Time: 5.106 ms  
  - planning: 4.993 ms  
  - execution: 0.113 ms  
    - I/O read: 0.000 ms  
    - I/O write: 0.000 ms  
  
Shared buffers:  
  - hits: 12 (~96.00 KiB) from the buffer pool  
  - reads: 0 from the OS file cache, including disk I/O  
  - dirtied: 0  
  - writes: 0  

Looks good

Note: Skipped asc since the plan is almost identical to the one above, except with ascending instead of descending order.

MR acceptance checklist

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

#396559 (closed)

Edited by Laura Montemayor

Merge request reports

Loading