Sha256: ca24584744796d0df6e403210da70ad741e4b76db5e9e96fb97a596e4d808530
Contents?: true
Size: 1.7 KB
Versions: 40
Compression:
Stored size: 1.7 KB
Contents
require_relative 'sortable/relation_safe_sort' class Eco::API::UseCases::GraphQL::Helpers::Location::Command::Diffs module Stages module Sortable # from what diffs size we should use the cluster mode CLUSTER_MODE_FROM = 400 class << self def included(base) super base.extend(Stages) end end private def diffs_sort(list, cluster_mode: nil, &block) RelationSafeSort.new(list, cluster_mode: cluster_mode, &block).sort end # @note As can't update archived nodes, it happens before :id update (:prev), # and therefore it should use `:prev` rather than `:curr` # @note you wouldn't be able to unarchive a node that does not exist. # Therefore, it does have `:prev` # @see spaceship operator `self.class#<=>` def cluster_mode(stage) case stage when :archive, :unarchive :prev when :insert :curr else return :curr if self.class.after_id_update?(stage) :prev end end def sort_top_to_bottom(raw_diffs, stage) clustered = nil clustered = cluster_mode(stage) if raw_diffs.count > CLUSTER_MODE_FROM if self.class.during_or_after_move?(stage) diffs_sort(raw_diffs, cluster_mode: clustered) do |a, b| a.sort_after_move(b) end else diffs_sort(raw_diffs, cluster_mode: clustered) do |a, b| a.sort_before_move(b) end end end def sort_bottom_to_top(raw_diffs, stage) sort_top_to_bottom(raw_diffs, stage).reverse end end end end
Version data entries
40 entries across 40 versions & 1 rubygems