From b6635283aec55ff4fbdc8cc53d9dc9b2e808651e Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Sun, 5 Sep 2021 17:32:13 +0200 Subject: [PATCH] use $lookup.pipeline for the relay pager --- modules/relay/src/main/RelayPager.scala | 38 ++++++++++--------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/modules/relay/src/main/RelayPager.scala b/modules/relay/src/main/RelayPager.scala index 2acd2697fa..2f0c2b614b 100644 --- a/modules/relay/src/main/RelayPager.scala +++ b/modules/relay/src/main/RelayPager.scala @@ -25,29 +25,21 @@ final class RelayPager(tourRepo: RelayTourRepo, roundRepo: RelayRoundRepo)(impli Match(tourRepo.selectors.official ++ tourRepo.selectors.inactive) -> List( Sort(Descending("syncedAt")), PipelineOperator( - $doc( - "$lookup" -> $doc( - "from" -> roundRepo.coll.name, - "as" -> "round", - "let" -> $doc("id" -> "$_id"), - "pipeline" -> $arr( - $doc( - "$match" -> $doc( - "$expr" -> $doc( - $doc("$eq" -> $arr("$tourId", "$$id")) - ) - ) - ), - $doc( - "$sort" -> $doc( - "startedAt" -> -1, - "startsAt" -> -1, - "name" -> -1 - ) - ), - $doc("$limit" -> 1), - $doc("$addFields" -> $doc("sync.log" -> $arr())) - ) + $lookup.pipeline( + from = roundRepo.coll, + as = "round", + local = "_id", + foreign = "tourId", + pipeline = List( + $doc( + "$sort" -> $doc( + "startedAt" -> -1, + "startsAt" -> -1, + "name" -> -1 + ) + ), + $doc("$limit" -> 1), + $doc("$addFields" -> $doc("sync.log" -> $arr())) ) ) ),