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
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/api/ci/runners.rb25
-rw-r--r--lib/gitlab/dependency_linker/base_linker.rb10
-rw-r--r--lib/gitlab/middleware/unauthenticated_session_expiry.rb3
3 files changed, 24 insertions, 14 deletions
diff --git a/lib/api/ci/runners.rb b/lib/api/ci/runners.rb
index 17bee275c51..300c30faf4a 100644
--- a/lib/api/ci/runners.rb
+++ b/lib/api/ci/runners.rb
@@ -94,6 +94,14 @@ module API
forbidden!("No access granted") unless can?(current_user, :read_builds, runner)
end
+
+ def preload_job_associations(jobs)
+ jobs.preload( # rubocop: disable CodeReuse/ActiveRecord -- this preload is tightly related to the endpoint
+ :user,
+ { pipeline: { project: [:route, { namespace: :route }] } },
+ { project: [:route, { namespace: :route }] }
+ )
+ end
end
resource :runners do
@@ -217,25 +225,24 @@ module API
end
params do
requires :id, type: Integer, desc: 'The ID of a runner'
+ optional :system_id, type: String, desc: 'System ID associated with the runner manager'
optional :status, type: String, desc: 'Status of the job', values: ::Ci::Build::AVAILABLE_STATUSES
optional :order_by, type: String, desc: 'Order by `id`', values: ::Ci::RunnerJobsFinder::ALLOWED_INDEXED_COLUMNS
optional :sort, type: String, values: %w[asc desc], default: 'desc', desc: 'Sort by `asc` or `desc` order. ' \
- 'Specify `order_by` as well, including for `id`'
+ 'Specify `order_by` as well, including for `id`'
+ optional :cursor, type: String, desc: 'Cursor for obtaining the next set of records'
use :pagination
end
get ':id/jobs' do
runner = get_runner(params[:id])
authenticate_list_runners_jobs!(runner)
+ # Optimize query when filtering by runner managers by not asking for count
+ paginator_params = params[:pagination] == :keyset || params[:system_id].blank? ? {} : { without_count: true }
+
jobs = ::Ci::RunnerJobsFinder.new(runner, current_user, params).execute
- jobs = jobs.preload( # rubocop: disable CodeReuse/ActiveRecord
- [
- :user,
- { pipeline: { project: [:route, { namespace: :route }] } },
- { project: [:route, { namespace: :route }] }
- ]
- )
- jobs = paginate(jobs)
+ jobs = preload_job_associations(jobs)
+ jobs = paginate_with_strategies(jobs, paginator_params: paginator_params)
jobs.each(&:commit) # batch loads all commits in the page
present jobs, with: Entities::Ci::JobBasicWithProject
diff --git a/lib/gitlab/dependency_linker/base_linker.rb b/lib/gitlab/dependency_linker/base_linker.rb
index 74bec55253f..2c9b559c8dc 100644
--- a/lib/gitlab/dependency_linker/base_linker.rb
+++ b/lib/gitlab/dependency_linker/base_linker.rb
@@ -31,13 +31,15 @@ module Gitlab
end
def external_url(name, external_ref)
- return if GIT_INVALID_URL_REGEX.match?(external_ref)
+ ref = external_ref.to_s
- case external_ref
+ return if GIT_INVALID_URL_REGEX.match?(ref)
+
+ case ref
when /\A#{URL_REGEX}\z/o
- external_ref
+ ref
when /\A#{REPO_REGEX}\z/o
- github_url(external_ref)
+ github_url(ref)
else
package_url(name)
end
diff --git a/lib/gitlab/middleware/unauthenticated_session_expiry.rb b/lib/gitlab/middleware/unauthenticated_session_expiry.rb
index f240a6b23bd..7c5c523c287 100644
--- a/lib/gitlab/middleware/unauthenticated_session_expiry.rb
+++ b/lib/gitlab/middleware/unauthenticated_session_expiry.rb
@@ -18,8 +18,9 @@ module Gitlab
result = @app.call(env)
warden = env['warden']
+ user = catch(:warden) { warden && warden.user } # rubocop:disable Cop/BanCatchThrow -- ignore Warden errors since we're outside Warden::Manager
- unless warden && warden.user
+ unless user
# This works because Rack uses these options every time a request is handled, and redis-store
# uses the Rack setting first:
# 1. https://github.com/rack/rack/blob/fdcd03a3c5a1c51d1f96fc97f9dfa1a9deac0c77/lib/rack/session/abstract/id.rb#L342