2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-20 21:29:54 +02:00
|
|
|
module Connections
|
2023-07-21 16:20:31 +02:00
|
|
|
class DossiersConnection < CursorConnection
|
2022-07-20 21:29:54 +02:00
|
|
|
def initialize(items, lookahead: nil, **kwargs)
|
|
|
|
super(items, **kwargs)
|
|
|
|
@lookahead = lookahead
|
|
|
|
end
|
|
|
|
|
2023-10-26 11:42:56 +02:00
|
|
|
def load_nodes
|
2022-07-20 21:29:54 +02:00
|
|
|
if @nodes.nil? && preload?
|
|
|
|
DossierPreloader.new(super).all
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2023-07-21 16:20:31 +02:00
|
|
|
def order_column
|
|
|
|
arguments[:updated_since].present? ? :updated_at : :depose_at
|
|
|
|
end
|
|
|
|
|
|
|
|
def order_table
|
|
|
|
:dossiers
|
|
|
|
end
|
|
|
|
|
2022-07-20 21:29:54 +02:00
|
|
|
# We check if the query selects champs form dossier. If it's the case we preload the dossier.
|
|
|
|
def preload?
|
|
|
|
@lookahead.selection(:nodes).selects?(:champs) || @lookahead.selection(:nodes).selects?(:annotations)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|