Commit b4d8dab2 authored by Adam Hegyi's avatar Adam Hegyi

Merge branch 'simple-order-builder-compact-nil-order-values' into 'master'

Compact order values

See merge request gitlab-org/gitlab!84549
parents 2f887f91 ade72227
......@@ -10,6 +10,7 @@ class Event < ApplicationRecord
include UsageStatistics
include ShaAttribute
# TODO https://gitlab.com/gitlab-org/gitlab/-/issues/358088
default_scope { reorder(nil) } # rubocop:disable Cop/DefaultScope
ACTIONS = HashWithIndifferentAccess.new(
......
......@@ -19,7 +19,9 @@ module Gitlab
def initialize(scope:)
@scope = scope
@order_values = scope.order_values
# We need to run 'compact' because 'nil' is not removed from order_values
# in some cases due to the use of 'default_scope'.
@order_values = scope.order_values.compact
@model_class = scope.model
@arel_table = @model_class.arel_table
@primary_key = @model_class.primary_key
......
......@@ -20,6 +20,22 @@ RSpec.describe Gitlab::Pagination::Keyset::SimpleOrderBuilder do
expect(column_definition).to be_not_nullable
expect(column_definition).to be_distinct
end
context "when the order scope's model uses default_scope" do
let(:scope) do
model = Class.new(ApplicationRecord) do
self.table_name = 'events'
default_scope { reorder(nil) } # rubocop:disable Cop/DefaultScope
end
model.reorder(nil)
end
it 'orders by primary key' do
expect(sql_with_order).to end_with('ORDER BY "events"."id" DESC')
end
end
end
context 'when primary key order present' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment