From 7ad920ca655fc212a0d5c74deb0fa50e1c8a3300 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Thu, 14 Oct 2021 08:28:37 +0200 Subject: [PATCH] use $lookup.pipeline in DailyPuzzle --- modules/clas/src/main/ClasApi.scala | 2 +- modules/db/src/main/dsl.scala | 10 +++++--- modules/msg/src/main/MsgApi.scala | 2 +- modules/puzzle/src/main/DailyPuzzle.scala | 28 ++++++++------------- modules/relay/src/main/RelayApi.scala | 2 +- modules/relay/src/main/RelayPager.scala | 2 +- modules/ublog/src/main/UblogPaginator.scala | 2 +- 7 files changed, 22 insertions(+), 26 deletions(-) diff --git a/modules/clas/src/main/ClasApi.scala b/modules/clas/src/main/ClasApi.scala index 49969e0f25..0df3836857 100644 --- a/modules/clas/src/main/ClasApi.scala +++ b/modules/clas/src/main/ClasApi.scala @@ -100,7 +100,7 @@ final class ClasApi( as = "clas", local = "clasId", foreign = "_id", - pipeline = List( + pipe = List( $doc( "$match" -> $doc( "$expr" -> $doc("$in" -> $arr(teacher, "$teachers")) diff --git a/modules/db/src/main/dsl.scala b/modules/db/src/main/dsl.scala index 4315ea5d9e..ab3933eabc 100644 --- a/modules/db/src/main/dsl.scala +++ b/modules/db/src/main/dsl.scala @@ -355,10 +355,10 @@ trait dsl { simple(from.name, as, local, foreign) def simple(from: AsyncColl, as: String, local: String, foreign: String): Bdoc = simple(from.name.value, as, local, foreign) - def pipeline(from: Coll, as: String, local: String, foreign: String, pipeline: List[Bdoc]): Bdoc = + def pipeline(from: String, as: String, local: String, foreign: String, pipe: List[Bdoc]): Bdoc = $doc( "$lookup" -> $doc( - "from" -> from.name, + "from" -> from, "as" -> as, "let" -> $doc("local" -> s"$$$local"), "pipeline" -> { @@ -366,10 +366,14 @@ trait dsl { "$match" -> $doc( "$expr" -> $doc($doc("$eq" -> $arr(s"$$$foreign", "$$local"))) ) - ) :: pipeline + ) :: pipe } ) ) + def pipeline(from: Coll, as: String, local: String, foreign: String, pipe: List[Bdoc]): Bdoc = + pipeline(from.name, as, local, foreign, pipe) + def pipeline(from: AsyncColl, as: String, local: String, foreign: String, pipe: List[Bdoc]): Bdoc = + pipeline(from.name.value, as, local, foreign, pipe) } implicit class ElementBuilderLike(val field: String) diff --git a/modules/msg/src/main/MsgApi.scala b/modules/msg/src/main/MsgApi.scala index 7cbb38084f..6149841119 100644 --- a/modules/msg/src/main/MsgApi.scala +++ b/modules/msg/src/main/MsgApi.scala @@ -188,7 +188,7 @@ final class MsgApi( as = "msgs", local = "_id", foreign = "tid", - pipeline = List( + pipe = List( $doc("$sort" -> $sort.desc("date")), $doc("$limit" -> 11), $doc("$project" -> msgProjection) diff --git a/modules/puzzle/src/main/DailyPuzzle.scala b/modules/puzzle/src/main/DailyPuzzle.scala index 420e61ec13..c7b4d3af2c 100644 --- a/modules/puzzle/src/main/DailyPuzzle.scala +++ b/modules/puzzle/src/main/DailyPuzzle.scala @@ -58,24 +58,16 @@ final private[puzzle] class DailyPuzzle( Project($doc("ids" -> true, "_id" -> false)), UnwindField("ids"), PipelineOperator( - $doc( - "$lookup" -> $doc( - "from" -> colls.puzzle.name.value, - "as" -> "puzzle", - "let" -> $doc("id" -> "$ids"), - "pipeline" -> $arr( - $doc( - "$match" -> $doc( - "$expr" -> $doc( - $doc("$eq" -> $arr("$_id", "$$id")) - ) - ) - ), - $doc( - "$match" -> $doc( - Puzzle.BSONFields.day $exists false, - Puzzle.BSONFields.themes $ne PuzzleTheme.oneMove.key.value - ) + $lookup.pipeline( + from = colls.puzzle, + as = "puzzle", + local = "ids", + foreign = "_id", + pipe = List( + $doc( + "$match" -> $doc( + Puzzle.BSONFields.day $exists false, + Puzzle.BSONFields.themes $ne PuzzleTheme.oneMove.key.value ) ) ) diff --git a/modules/relay/src/main/RelayApi.scala b/modules/relay/src/main/RelayApi.scala index 14c112fdb9..5b71d80112 100644 --- a/modules/relay/src/main/RelayApi.scala +++ b/modules/relay/src/main/RelayApi.scala @@ -257,7 +257,7 @@ final class RelayApi( as = "rounds", local = "_id", foreign = "tourId", - pipeline = List( + pipe = List( $doc("$sort" -> $doc("startedAt" -> 1, "startsAt" -> 1, "name" -> 1)) ) ) diff --git a/modules/relay/src/main/RelayPager.scala b/modules/relay/src/main/RelayPager.scala index 2f0c2b614b..3bc610478b 100644 --- a/modules/relay/src/main/RelayPager.scala +++ b/modules/relay/src/main/RelayPager.scala @@ -30,7 +30,7 @@ final class RelayPager(tourRepo: RelayTourRepo, roundRepo: RelayRoundRepo)(impli as = "round", local = "_id", foreign = "tourId", - pipeline = List( + pipe = List( $doc( "$sort" -> $doc( "startedAt" -> -1, diff --git a/modules/ublog/src/main/UblogPaginator.scala b/modules/ublog/src/main/UblogPaginator.scala index 4835ef94f2..52719eb10e 100644 --- a/modules/ublog/src/main/UblogPaginator.scala +++ b/modules/ublog/src/main/UblogPaginator.scala @@ -86,7 +86,7 @@ final class UblogPaginator( as = "blog", local = "blog", foreign = "_id", - pipeline = List( + pipe = List( $doc( "$match" -> $doc( "$expr" -> $doc("$gte" -> $arr("$tier", UblogBlog.Tier.LOW))