diff options
Diffstat (limited to 'lib/gitlab/pagination/keyset')
-rw-r--r-- | lib/gitlab/pagination/keyset/cursor_pager.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/pagination/keyset/pager.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/pagination/keyset/simple_order_builder.rb | 32 |
3 files changed, 2 insertions, 34 deletions
diff --git a/lib/gitlab/pagination/keyset/cursor_pager.rb b/lib/gitlab/pagination/keyset/cursor_pager.rb index 0b49aa87a02..d8fa94091ea 100644 --- a/lib/gitlab/pagination/keyset/cursor_pager.rb +++ b/lib/gitlab/pagination/keyset/cursor_pager.rb @@ -10,7 +10,7 @@ module Gitlab @cursor_based_request_context = cursor_based_request_context end - def paginate(relation) + def paginate(relation, _params = {}) @paginator ||= relation.keyset_paginate( per_page: cursor_based_request_context.per_page, cursor: cursor_based_request_context.cursor diff --git a/lib/gitlab/pagination/keyset/pager.rb b/lib/gitlab/pagination/keyset/pager.rb index 6a2ae20f3b8..3fabd454ee3 100644 --- a/lib/gitlab/pagination/keyset/pager.rb +++ b/lib/gitlab/pagination/keyset/pager.rb @@ -10,7 +10,7 @@ module Gitlab @request = request end - def paginate(relation) + def paginate(relation, _params = {}) # Validate assumption: The last two columns must match the page order_by validate_order!(relation) diff --git a/lib/gitlab/pagination/keyset/simple_order_builder.rb b/lib/gitlab/pagination/keyset/simple_order_builder.rb index 318720c77d1..cbd523389d6 100644 --- a/lib/gitlab/pagination/keyset/simple_order_builder.rb +++ b/lib/gitlab/pagination/keyset/simple_order_builder.rb @@ -11,8 +11,6 @@ module Gitlab # [transformed_scope, true] # true indicates that the new scope was successfully built # [orginal_scope, false] # false indicates that the order values are not supported in this class class SimpleOrderBuilder - NULLS_ORDER_REGEX = /(?<column_name>.*) (?<direction>\bASC\b|\bDESC\b) (?<nullable>\bNULLS LAST\b|\bNULLS FIRST\b)/.freeze - def self.build(scope) new(scope: scope).build end @@ -90,32 +88,6 @@ module Gitlab end end - # This method converts the first order value to a corresponding arel expression - # if the order value uses either NULLS LAST or NULLS FIRST ordering in raw SQL. - # - # TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/356644 - # We should stop matching raw literals once we switch to using the Arel methods. - def convert_raw_nulls_order! - order_value = order_values.first - - return unless order_value.is_a?(Arel::Nodes::SqlLiteral) - - # Detect NULLS LAST or NULLS FIRST ordering by looking at the raw SQL string. - if matches = order_value.match(NULLS_ORDER_REGEX) - return unless table_column?(matches[:column_name]) - - column_attribute = arel_table[matches[:column_name]] - direction = matches[:direction].downcase.to_sym - nullable = matches[:nullable].downcase.parameterize(separator: '_').to_sym - - # Build an arel order expression for NULLS ordering. - order = direction == :desc ? column_attribute.desc : column_attribute.asc - arel_order_expression = nullable == :nulls_first ? order.nulls_first : order.nulls_last - - order_values[0] = arel_order_expression - end - end - def nullability(order_value, attribute_name) nullable = model_class.columns.find { |column| column.name == attribute_name }.null @@ -206,16 +178,12 @@ module Gitlab def ordered_by_other_column? return unless order_values.one? - convert_raw_nulls_order! - supported_column?(order_values.first) end def ordered_by_other_column_with_tie_breaker? return unless order_values.size == 2 - convert_raw_nulls_order! - return unless supported_column?(order_values.first) tie_breaker_attribute = order_values.second.try(:expr) |