Commit afedb86e authored by Dan Jensen's avatar Dan Jensen

Add order_by updated_at to Pipelines API

This allows order_by updated_at on the Pipelines API so users can query
for the most recent updates. It adds a database index to ensure the
feature is performant.
parent a658e852
......@@ -3,7 +3,7 @@
class PipelinesFinder
attr_reader :project, :pipelines, :params, :current_user
ALLOWED_INDEXED_COLUMNS = %w[id status ref user_id].freeze
ALLOWED_INDEXED_COLUMNS = %w[id status ref updated_at user_id].freeze
def initialize(project, current_user, params = {})
@project = project
......
---
title: Allow order_by updated_at in Pipelines API
merge_request: 19886
author:
type: added
# frozen_string_literal: true
class AddIndexOnCiPipelinesUpdatedAt < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
INDEX_COLUMNS = [:project_id, :status, :updated_at]
disable_ddl_transaction!
def up
add_concurrent_index(:ci_pipelines, INDEX_COLUMNS)
end
def down
remove_concurrent_index(:ci_pipelines, INDEX_COLUMNS)
end
end
......@@ -846,6 +846,7 @@ ActiveRecord::Schema.define(version: 2019_11_12_115317) do
t.index ["project_id", "sha"], name: "index_ci_pipelines_on_project_id_and_sha"
t.index ["project_id", "source"], name: "index_ci_pipelines_on_project_id_and_source"
t.index ["project_id", "status", "config_source"], name: "index_ci_pipelines_on_project_id_and_status_and_config_source"
t.index ["project_id", "status", "updated_at"], name: "index_ci_pipelines_on_project_id_and_status_and_updated_at"
t.index ["project_id"], name: "index_ci_pipelines_on_project_id"
t.index ["status"], name: "index_ci_pipelines_on_status"
t.index ["user_id"], name: "index_ci_pipelines_on_user_id"
......
......@@ -18,7 +18,7 @@ GET /projects/:id/pipelines
| `yaml_errors`| boolean | no | Returns pipelines with invalid configurations |
| `name`| string | no | The name of the user who triggered pipelines |
| `username`| string | no | The username of the user who triggered pipelines |
| `order_by`| string | no | Order pipelines by `id`, `status`, `ref`, or `user_id` (default: `id`) |
| `order_by`| string | no | Order pipelines by `id`, `status`, `ref`, `updated_at` or `user_id` (default: `id`) |
| `sort` | string | no | Sort pipelines in `asc` or `desc` order (default: `desc`) |
```
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment