lib/picky/query/allocation.rb in picky-4.22.0 vs lib/picky/query/allocation.rb in picky-4.23.0
- old
+ new
@@ -82,24 +82,26 @@
#
# Parameters:
# * amount: The amount of ids to calculate.
# * offset: The offset to calculate them from.
#
- def process! amount, offset
+ def process! amount, offset, sorting = nil
calculated_ids = calculate_ids amount, offset
+ calculated_ids.sort_by! &sorting if sorting
@count = calculated_ids.size # cache the count before throwing away the ids
@ids = calculated_ids.slice!(offset, amount) || [] # slice out the relevant part
end
# Same as the above, but with illegal ids. Parameter added:
# * illegal_ids: ids to ignore.
#
- def process_with_illegals! amount, offset, illegal_ids
+ def process_with_illegals! amount, offset, illegal_ids, sorting = nil
# Note: Fairly inefficient calculation since it
# assumes the worst case that the ids contain
# all illegal ids.
#
calculated_ids = calculate_ids amount + illegal_ids.size, offset
calculated_ids = calculated_ids - illegal_ids
+ calculated_ids.sort_by! &sorting if sorting
@count = calculated_ids.size # cache the count before throwing away the ids
@ids = calculated_ids.slice!(offset, amount) || [] # slice out the relevant part
end
#
\ No newline at end of file