Skip to content

Backend: Add option to sort CI catalog resources by usage count in GraphQl

Summary

One of our objectives with CI Catalog instrumentation is to enable users to sort Catalog Resources (aka "Catalog Projects") by popularity (usage count).

The bulk of the BE work to support this feature was done as part of #440382 (closed). In !147293 (merged), we introduced the columns last_30_day_usage_count and last_30_day_usage_count_updated_at to the catalog_resources table. These columns will be populated by the effort in Backend: Implement daily worker to aggregate la... (#452545 - closed).

In this issue, we need to expose last_30_day_usage_count and add the option to sort by usage in GraphQl.

Proposal

Add USAGE_COUNT_ASC AND USAGE_COUNT_DESC as sort options to Ci::Catalog::ResourceType. Also, expose the last_30_day_usage_count column.

We should be able to query the catalog resources like so:

Sort catalog resources by usage count

query getSortedCatalogResources {
  ciCatalogResources(sort: USAGE_COUNT_DESC) {
    nodes {
      id
      last30DayUsageCount
    }
  }
}

Implementation Table

Group Issue Link
backend Spike: Evaluate how to calculate number of time... (#438409 - closed)
backend Backend: Component usage instrumentation (#440382 - closed)
backend Backend: Implement daily worker to aggregate la... (#452545 - closed)
backend 👈 You are here
frontend Frontend: Show usage statistics and sort option... (#434333 - closed)
frontend Frontend: Present the number of times a single ... (#443632 - closed)
backend Backend: Reduce data retention period and store... (#443681)
backend Backend: Implement individual component sorting... (#453975 - closed)
Edited by Leaminn Ma