Commit 4c61c2aa authored by Andreas Brandl's avatar Andreas Brandl

Tidy up assumption check

parent dff3ba49
...@@ -11,8 +11,8 @@ module Gitlab ...@@ -11,8 +11,8 @@ module Gitlab
end end
def paginate(relation) def paginate(relation)
# Validate an assumption we're making (TODO: subject to be removed) # Validate assumption: The last two columns must match the page order_by
check_order!(relation) raise "Page's order_by doesnt match the relation's order: #{present_order} vs #{page.order_by}" unless correct_order?(relation)
# This performs the database query and retrieves records # This performs the database query and retrieves records
# We retrieve one record more to check if we have data beyond this page # We retrieve one record more to check if we have data beyond this page
...@@ -43,23 +43,10 @@ module Gitlab ...@@ -43,23 +43,10 @@ module Gitlab
@page ||= request.page @page ||= request.page
end end
def order_by(rel) def correct_order?(rel)
rel.order_values.map { |val| [val.expr.name, val.direction] } present_order = rel.order_values.map { |val| [val.expr.name, val.direction] }.last(2).to_h
end
def check_order!(rel)
present_order = order_by(rel).last(2).to_h
if to_sym_vals(page.order_by) != to_sym_vals(present_order)
# The last two columns must match the page order_by
raise "Page order_by doesnt match the relation\'s order: #{present_order} vs #{page.order_by}"
end
end
def to_sym_vals(hash) page.order_by.with_indifferent_access == present_order.with_indifferent_access
hash.each_with_object({}) do |(k, v), h|
h[k&.to_sym] = v&.to_sym
end
end end
end end
end end
......
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