Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-12-16 18:10:28 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-12-16 18:10:28 +0300
commit6aaec2fc6c3e3f96f443b96fd53ae9ed5e7979af (patch)
tree17336eb6c5d10d904310218c72b3b0bf9b78a180 /app/finders/packages/build_infos_finder.rb
parenta32fd79d1e34ca4da1d5390c0aaf91d660e03fc8 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/finders/packages/build_infos_finder.rb')
-rw-r--r--app/finders/packages/build_infos_finder.rb68
1 files changed, 68 insertions, 0 deletions
diff --git a/app/finders/packages/build_infos_finder.rb b/app/finders/packages/build_infos_finder.rb
new file mode 100644
index 00000000000..92ad5888eb9
--- /dev/null
+++ b/app/finders/packages/build_infos_finder.rb
@@ -0,0 +1,68 @@
+# frozen_string_literal: true
+
+module Packages
+ class BuildInfosFinder
+ MAX_PAGE_SIZE = 100
+
+ def initialize(package, params)
+ @package = package
+ @params = params
+ end
+
+ def execute
+ build_infos = @package.build_infos.without_empty_pipelines
+ build_infos = apply_order(build_infos)
+ build_infos = apply_limit(build_infos)
+ apply_cursor(build_infos)
+ end
+
+ private
+
+ def apply_order(build_infos)
+ order_direction = :desc
+ order_direction = :asc if last
+
+ build_infos.order_by_pipeline_id(order_direction)
+ end
+
+ def apply_limit(build_infos)
+ limit = [first, last, max_page_size, MAX_PAGE_SIZE].compact.min
+ limit += 1 if support_next_page
+ build_infos.limit(limit)
+ end
+
+ def apply_cursor(build_infos)
+ if before
+ build_infos.with_pipeline_id_greater_than(before)
+ elsif after
+ build_infos.with_pipeline_id_less_than(after)
+ else
+ build_infos
+ end
+ end
+
+ def first
+ @params[:first]
+ end
+
+ def last
+ @params[:last]
+ end
+
+ def max_page_size
+ @params[:max_page_size]
+ end
+
+ def before
+ @params[:before]
+ end
+
+ def after
+ @params[:after]
+ end
+
+ def support_next_page
+ @params[:support_next_page]
+ end
+ end
+end