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-09-07 12:11:43 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-09-07 12:11:43 +0300
commit378308b6cde44eb1a320b9202ff8946a911f35f6 (patch)
tree3031a645455dbbcdb2961dd09c15100fa28ed8e1 /lib/gitlab
parent777dc3053f8433a9f5c9cc868325e16eac5d93e5 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab')
-rw-r--r--lib/gitlab/database/load_balancing/sidekiq_client_middleware.rb6
-rw-r--r--lib/gitlab/database/load_balancing/sidekiq_server_middleware.rb2
-rw-r--r--lib/gitlab/database_importers/work_items/base_type_importer.rb15
-rw-r--r--lib/gitlab/pagination/cursor_based_keyset.rb27
-rw-r--r--lib/gitlab/pagination/keyset/cursor_based_request_context.rb15
5 files changed, 55 insertions, 10 deletions
diff --git a/lib/gitlab/database/load_balancing/sidekiq_client_middleware.rb b/lib/gitlab/database/load_balancing/sidekiq_client_middleware.rb
index acb4842db31..518a812b406 100644
--- a/lib/gitlab/database/load_balancing/sidekiq_client_middleware.rb
+++ b/lib/gitlab/database/load_balancing/sidekiq_client_middleware.rb
@@ -32,12 +32,10 @@ module Gitlab
def set_data_consistency_locations!(job)
# Once we add support for multiple databases to our load balancer, we would use something like this:
# job['wal_locations'] = Gitlab::Database::DATABASES.transform_values do |connection|
- # connection.load_balancer.primary_write_location.
+ # connection.load_balancer.primary_write_location
# end
#
- # TODO: Replace hardcoded database config name :main when we merge unification strategy
- # https://gitlab.com/gitlab-org/gitlab/-/issues/336566
- job['wal_locations'] = { main: wal_location } if wal_location
+ job['wal_locations'] = { Gitlab::Database::MAIN_DATABASE_NAME.to_sym => wal_location } if wal_location
end
def wal_location
diff --git a/lib/gitlab/database/load_balancing/sidekiq_server_middleware.rb b/lib/gitlab/database/load_balancing/sidekiq_server_middleware.rb
index 2555f693a5d..f7fda14b215 100644
--- a/lib/gitlab/database/load_balancing/sidekiq_server_middleware.rb
+++ b/lib/gitlab/database/load_balancing/sidekiq_server_middleware.rb
@@ -66,7 +66,7 @@ module Gitlab
def legacy_wal_location(job)
wal_location = job['database_write_location'] || job['database_replica_location']
- { main: wal_location } if wal_location
+ { Gitlab::Database::MAIN_DATABASE_NAME.to_sym => wal_location } if wal_location
end
def load_balancing_available?(worker_class)
diff --git a/lib/gitlab/database_importers/work_items/base_type_importer.rb b/lib/gitlab/database_importers/work_items/base_type_importer.rb
new file mode 100644
index 00000000000..c5acdb41de5
--- /dev/null
+++ b/lib/gitlab/database_importers/work_items/base_type_importer.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module DatabaseImporters
+ module WorkItems
+ module BaseTypeImporter
+ def self.import
+ WorkItem::Type::BASE_TYPES.each do |type, attributes|
+ WorkItem::Type.create!(base_type: type, **attributes.slice(:name, :icon_name))
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/pagination/cursor_based_keyset.rb b/lib/gitlab/pagination/cursor_based_keyset.rb
new file mode 100644
index 00000000000..f19cdf06d9a
--- /dev/null
+++ b/lib/gitlab/pagination/cursor_based_keyset.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Pagination
+ module CursorBasedKeyset
+ SUPPORTED_ORDERING = {
+ Group => { name: :asc }
+ }.freeze
+
+ def self.available_for_type?(relation)
+ SUPPORTED_ORDERING.key?(relation.klass)
+ end
+
+ def self.available?(cursor_based_request_context, relation)
+ available_for_type?(relation) &&
+ order_satisfied?(relation, cursor_based_request_context)
+ end
+
+ def self.order_satisfied?(relation, cursor_based_request_context)
+ order_by_from_request = cursor_based_request_context.order_by
+
+ SUPPORTED_ORDERING[relation.klass] == order_by_from_request
+ end
+ private_class_method :order_satisfied?
+ end
+ end
+end
diff --git a/lib/gitlab/pagination/keyset/cursor_based_request_context.rb b/lib/gitlab/pagination/keyset/cursor_based_request_context.rb
index d9c118ceef5..18390f5b59d 100644
--- a/lib/gitlab/pagination/keyset/cursor_based_request_context.rb
+++ b/lib/gitlab/pagination/keyset/cursor_based_request_context.rb
@@ -4,11 +4,12 @@ module Gitlab
module Pagination
module Keyset
class CursorBasedRequestContext
- attr_reader :request
- delegate :params, :header, to: :request
+ DEFAULT_SORT_DIRECTION = :desc
+ attr_reader :request_context
+ delegate :params, to: :request_context
- def initialize(request)
- @request = request
+ def initialize(request_context)
+ @request_context = request_context
end
def per_page
@@ -21,9 +22,13 @@ module Gitlab
def apply_headers(cursor_for_next_page)
Gitlab::Pagination::Keyset::HeaderBuilder
- .new(self)
+ .new(request_context)
.add_next_page_header({ cursor: cursor_for_next_page })
end
+
+ def order_by
+ { params[:order_by].to_sym => params[:sort]&.to_sym || DEFAULT_SORT_DIRECTION }
+ end
end
end
end