Class: DeploymentsFinder

Inherits:
Object
  • Object
show all
Includes:
UpdatedAtFilter
Defined in:
app/finders/deployments_finder.rb

Overview

WARNING: This finder does not check permissions!

Arguments:

params:
  project: Project model - Find deployments for this project
  updated_after: DateTime
  updated_before: DateTime
  finished_after: DateTime
  finished_before: DateTime
  environment: String (name) or Integer (ID)
  status: String or Array<String> (see Deployment.statuses)
  order_by: String (see ALLOWED_SORT_VALUES constant)
  sort: String (asc | desc)

Constant Summary collapse

ALLOWED_SORT_VALUES =

Warning: These const are directly used in Deployment Rest API, thus modifying these values could implicity change the API interface or introduce a breaking change. Also, if you add a sort value, make sure that the new query will stay performant with the other filtering/sorting parameters. The composed query could be significantly slower when the filtering and sorting columns are different. See gitlab.com/gitlab-org/gitlab/-/issues/325627 for example.

%w[id iid created_at updated_at finished_at].freeze
DEFAULT_SORT_VALUE =
'id'
ALLOWED_SORT_DIRECTIONS =
%w[asc desc].freeze
DEFAULT_SORT_DIRECTION =
'asc'
InefficientQueryError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from UpdatedAtFilter

#by_updated_at

Constructor Details

#initialize(params = {}) ⇒ DeploymentsFinder

Returns a new instance of DeploymentsFinder.



36
37
38
39
40
41
# File 'app/finders/deployments_finder.rb', line 36

def initialize(params = {})
  @params = params
  @params[:status] = Array(@params[:status]).map(&:to_s) if @params[:status]

  validate!
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



19
20
21
# File 'app/finders/deployments_finder.rb', line 19

def params
  @params
end

Instance Method Details

#executeObject



43
44
45
46
47
48
49
50
51
# File 'app/finders/deployments_finder.rb', line 43

def execute
  items = init_collection
  items = by_updated_at(items)
  items = by_finished_at(items)
  items = by_environment(items)
  items = by_status(items)
  items = preload_associations(items)
  sort(items)
end