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
|
|
|
|
|
|
|
|
def nodes
|
|
|
|
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
|