export game notes

This commit is contained in:
Thibault Duplessis 2021-04-14 08:35:53 +02:00
parent 9f87e846f7
commit ab3cd06406
2 changed files with 41 additions and 1 deletions

View file

@ -19,6 +19,7 @@ final class PersonalDataExport(
msgEnv: lila.msg.Env,
forumEnv: lila.forum.Env,
gameEnv: lila.game.Env,
roundEnv: lila.round.Env,
chatEnv: lila.chat.Env,
relationEnv: lila.relation.Env,
userRepo: lila.user.UserRepo,
@ -106,9 +107,46 @@ final class PersonalDataExport(
.map { doc => doc.string("l").??(_.drop(user.id.size + 1)) }
.throttle(heavyPerSecond, 1 second)
val gameNotes =
Source(List(textTitle("Game notes"))) concat
gameEnv.gameRepo.coll
.aggregateWith[Bdoc](
readPreference = ReadPreference.secondaryPreferred
) { framework =>
import framework._
List(
Match($doc(Game.BSONFields.playerUids -> user.id)),
Project($id(true)),
PipelineOperator(
$doc(
"$lookup" -> $doc(
"from" -> roundEnv.noteApi.collName,
"as" -> "note",
"let" -> $doc("id" -> $doc("$concat" -> $arr("$_id", user.id))),
"pipeline" -> $arr(
$doc(
"$match" -> $doc(
"$expr" -> $doc(
"$eq" -> $arr("$_id", "$$id")
)
)
)
)
)
)
),
Unwind("note"),
ReplaceRootField("note"),
Project($doc("_id" -> false, "t" -> true))
)
}
.documentSource()
.map { doc => ~doc.string("t") }
.throttle(heavyPerSecond, 1 second)
val outro = Source(List(textTitle("End of data export.")))
List(intro, connections, followedUsers, forumPosts, privateMessages, gameChats, outro)
List(intro, connections, followedUsers, forumPosts, privateMessages, gameChats, gameNotes, outro)
.foldLeft(Source.empty[String])(_ concat _)
}

View file

@ -6,6 +6,8 @@ import reactivemongo.api.bson._
final class NoteApi(coll: Coll)(implicit ec: scala.concurrent.ExecutionContext) {
def collName = coll.name
def get(gameId: String, userId: String): Fu[String] =
coll.primitiveOne[String]($id(makeId(gameId, userId)), "t") dmap (~_)