Skip to content

Commit

Permalink
Revert "Update to ReactiveMongo 0.12.0"
Browse files Browse the repository at this point in the history
This reverts commit 4ad2c23.
  • Loading branch information
ornicar committed Oct 25, 2016
1 parent e381b9b commit b821d8f
Show file tree
Hide file tree
Showing 32 changed files with 144 additions and 199 deletions.
7 changes: 2 additions & 5 deletions modules/api/src/main/PgnDump.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ final class PgnDump(
}
}

def exportUserGames(userId: String): Enumerator[String] = {
import reactivemongo.play.iteratees.cursorProducer
GameRepo.sortedCursor(Query user userId, Query.sortCreated).
enumerator() &> toPgn
}
def exportUserGames(userId: String): Enumerator[String] =
GameRepo.sortedCursor(Query user userId, Query.sortCreated).enumerate() &> toPgn

def exportGamesFromIds(ids: List[String]): Enumerator[String] =
Enumerator.enumerate(ids grouped 50) &>
Expand Down
20 changes: 9 additions & 11 deletions modules/blog/src/main/Notifier.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,20 @@ private[blog] final class Notifier(
}

private def doSend(post: Document): Funit = {
import reactivemongo.play.iteratees.cursorProducer

val content = NewBlogPost(
id = NewBlogPost.Id(post.id),
slug = NewBlogPost.Slug(post.slug),
title = NewBlogPost.Title(~post.getText("blog.title")))
UserRepo.recentlySeenNotKidIdsCursor(DateTime.now minusWeeks 1)
.enumerator(500 * 1000) &> Enumeratee.map {
_.getAs[String]("_id") err "User without an id"
} |>>>
Iteratee.foldM[String, Int](0) {
case (count, userId) => notifyApi.addNotificationWithoutSkipOrEvent(
.enumerate(500 * 1000) &> Enumeratee.map {
_.getAs[String]("_id") err "User without an id"
} |>>>
Iteratee.foldM[String, Int](0) {
case (count, userId) => notifyApi.addNotificationWithoutSkipOrEvent(
Notification.make(Notification.Notifies(userId), content)
) inject (count + 1)
} addEffect { count =>
logger.info(s"Sent $count notifications")
} void
) inject (count + 1)
} addEffect { count =>
logger.info(s"Sent $count notifications")
} void
}
}
8 changes: 4 additions & 4 deletions modules/db/src/main/BSON.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ object BSON extends Handlers {
val b = collection.immutable.Map.newBuilder[String, V]
for (tuple <- bson.elements)
// assume that all values in the document are Bdocs
b += (tuple.name -> vr.read(tuple.value.asInstanceOf[Bdoc]))
b += (tuple._1 -> vr.read(tuple._2.asInstanceOf[Bdoc]))
b.result
}
}
Expand Down Expand Up @@ -82,7 +82,7 @@ object BSON extends Handlers {
val valueReader = vr.asInstanceOf[BSONReader[BSONValue, V]]
// mutable optimized implementation
val b = collection.immutable.Map.newBuilder[String, V]
for (tuple <- bson.elements) b += (tuple.name -> valueReader.read(tuple.value))
for (tuple <- bson.elements) b += (tuple._1 -> valueReader.read(tuple._2))
b.result
}
}
Expand All @@ -108,7 +108,7 @@ object BSON extends Handlers {
val map = {
// mutable optimized implementation
val b = collection.immutable.Map.newBuilder[String, BSONValue]
for (tuple <- doc.stream if tuple.isSuccess) b += (tuple.get.name -> tuple.get.value)
for (tuple <- doc.stream if tuple.isSuccess) b += (tuple.get._1 -> tuple.get._2)
b.result
}

Expand Down Expand Up @@ -194,7 +194,7 @@ object BSON extends Handlers {
}
def debugArr(doc: Barr): String = doc.values.toList.map(debug).mkString("[", ", ", "]")
def debugDoc(doc: Bdoc): String = (doc.elements.toList map {
case BSONElement(k, v) => s"$k: ${debug(v)}"
case (k, v) => s"$k: ${debug(v)}"
}).mkString("{", ", ", "}")

def hashDoc(doc: Bdoc): String = debugDoc(doc).replace(" ", "")
Expand Down
2 changes: 1 addition & 1 deletion modules/db/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class Env(
lifecycle: play.api.inject.ApplicationLifecycle) {

lazy val (connection, dbName) = {
val driver = MongoDriver(config)
val driver = new MongoDriver(Some(config))

registerDriverShutdownHook(driver)

Expand Down
20 changes: 8 additions & 12 deletions modules/db/src/main/dsl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import reactivemongo.api._
import reactivemongo.api.collections.GenericQueryBuilder
import reactivemongo.bson._

trait dsl extends LowPriorityDsl {
trait dsl {

type Coll = reactivemongo.api.collections.bson.BSONCollection
type Bdoc = BSONDocument
Expand Down Expand Up @@ -116,8 +116,7 @@ trait dsl extends LowPriorityDsl {
}

def $rename(item: (String, String), items: (String, String)*)(implicit writer: BSONWriter[String, _ <: BSONValue]): BSONDocument = {
$doc("$rename" -> $doc((item +: items).
map { case (k, v) => BSONElement(k, BSONString(v)) }))
$doc("$rename" -> $doc((Seq(item) ++ items).map(Producer.nameValue2Producer[String]): _*))
}

def $setOnInsert(item: Producer[BSONElement], items: Producer[BSONElement]*): BSONDocument = {
Expand All @@ -129,7 +128,7 @@ trait dsl extends LowPriorityDsl {
}

def $unset(field: String, fields: String*): BSONDocument = {
$doc("$unset" -> $doc((Seq(field) ++ fields).map(k => BSONElement(k, BSONString("")))))
$doc("$unset" -> $doc((Seq(field) ++ fields).map(_ -> BSONString(""))))
}

def $min(item: Producer[BSONElement]): BSONDocument = {
Expand Down Expand Up @@ -185,7 +184,7 @@ trait dsl extends LowPriorityDsl {
}

def $currentDate(items: (String, CurrentDateValueProducer[_])*): BSONDocument = {
$doc("$currentDate" -> $doc(items.map(item => BSONElement(item._1, item._2.produce))))
$doc("$currentDate" -> $doc(items.map(item => item._1 -> item._2.produce)))
}
// End of Top Level Field Update Operators
//**********************************************************************************************//
Expand Down Expand Up @@ -372,16 +371,13 @@ trait dsl extends LowPriorityDsl {
with LogicalOperators
with ArrayOperators

implicit def toBSONElement[V <: BSONValue](expression: Expression[V])(implicit writer: BSONWriter[V, _ <: BSONValue]): Producer[BSONElement] = {
expression.field -> expression.value
}

implicit def toBSONDocument[V <: BSONValue](expression: Expression[V])(implicit writer: BSONWriter[V, _ <: BSONValue]): BSONDocument =
$doc(expression.field -> expression.value)

}

sealed trait LowPriorityDsl { self: dsl =>
// Priority lower than toBSONDocument
implicit def toBSONElement[V <: BSONValue](expression: Expression[V])(implicit writer: BSONWriter[V, _ <: BSONValue]): Producer[BSONElement] = {
BSONElement(expression.field, expression.value)
}
}

object dsl extends dsl with CollExt with QueryBuilderExt with CursorExt with Handlers
8 changes: 3 additions & 5 deletions modules/evaluation/src/main/Assessible.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,10 @@ case class Assessible(analysed: Analysed) {
case PlayerFlags(T, T, T, T, T, T, T) => Cheating // all T, obvious cheat
case PlayerFlags(T, _, T, _, _, T, _) => Cheating // high accuracy, high blurs, no fast moves
case PlayerFlags(T, _, _, T, _, _, _) => Cheating // high accuracy, moderate blurs

case PlayerFlags(_, T, _, T, T, _, _) => LikelyCheating // always has advantage, moderate blurs, highly consistent move times

case PlayerFlags(_, _, _, T, T, _, _) => LikelyCheating // high accuracy, moderate blurs => 93% chance cheating
case PlayerFlags(T, _, _, _, _, _, T) => LikelyCheating // Holds are bad, hmk?
case PlayerFlags(_, T, _, _, _, _, T) => LikelyCheating // Holds are bad, hmk?

case PlayerFlags(T, _, _, _, _, _, T) => LikelyCheating // Holds are bad, hmk?
case PlayerFlags(_, T, _, _, _, _, T) => LikelyCheating // Holds are bad, hmk?
case PlayerFlags(_, T, T, _, _, _, _) => LikelyCheating // always has advantage, high blurs

case PlayerFlags(_, T, _, _, T, T, _) => Unclear // always has advantage, consistent move times
Expand Down
5 changes: 1 addition & 4 deletions modules/explorer/src/main/ExplorerIndexer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,11 @@ private final class ExplorerIndexer(
Query.turnsMoreThan(8) ++
Query.noProvisional ++
Query.bothRatingsGreaterThan(1501)

import reactivemongo.api._
import reactivemongo.play.iteratees.cursorProducer

gameColl.find(query)
.sort(Query.sortChronological)
.cursor[Game](ReadPreference.secondary)
.enumerator(maxGames) &>
.enumerate(maxGames, stopOnError = true) &>
Enumeratee.mapM[Game].apply[Option[GamePGN]] { game =>
makeFastPgn(game) map {
_ map { game -> _ }
Expand Down
5 changes: 2 additions & 3 deletions modules/forum/src/main/PostRepo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package lila.forum
import lila.db.dsl._
import lila.user.User.BSONFields
import org.joda.time.DateTime
import reactivemongo.api.{ CursorProducer, ReadPreference }
import reactivemongo.api.ReadPreference

object PostRepo extends PostRepo(false) {

Expand Down Expand Up @@ -77,7 +77,6 @@ sealed abstract class PostRepo(troll: Boolean) {

def cursor(
selector: Bdoc,
readPreference: ReadPreference = ReadPreference.secondaryPreferred)(
implicit cp: CursorProducer[Post]) =
readPreference: ReadPreference = ReadPreference.secondaryPreferred) =
coll.find(selector).cursor[Post](readPreference)
}
4 changes: 1 addition & 3 deletions modules/forumSearch/src/main/ForumSearchApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ final class ForumSearchApi(
Fields.troll -> view.post.troll,
Fields.date -> view.post.createdAt.getDate)

import reactivemongo.play.iteratees.cursorProducer

def reset = client match {
case c: ESClientHttp => c.putMapping >> {
import play.api.libs.iteratee._
Expand All @@ -46,7 +44,7 @@ final class ForumSearchApi(
PostRepo.cursor(
selector = $empty,
readPreference = ReadPreference.secondaryPreferred)
.enumerator(maxEntries) &>
.enumerate(maxEntries, stopOnError = true) &>
Enumeratee.grouped(Iteratee takeUpTo batchSize) |>>>
Iteratee.foldM[Seq[Post], Int](0) {
case (nb, posts) => for {
Expand Down
4 changes: 2 additions & 2 deletions modules/game/src/main/GameDiff.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import lila.db.ByteArray

private[game] object GameDiff {

type Set = BSONElement // [String, BSONValue]
type Unset = BSONElement //[String, BSONBoolean]
type Set = (String, BSONValue)
type Unset = (String, BSONBoolean)

def apply(a: Game, b: Game): (List[Set], List[Unset]) = {

Expand Down
14 changes: 6 additions & 8 deletions modules/game/src/main/GameRepo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import scala.util.Random
import chess.format.{ Forsyth, FEN }
import chess.{ Color, Status }
import org.joda.time.DateTime
import reactivemongo.api.{ CursorProducer, ReadPreference }
import reactivemongo.api.ReadPreference
import reactivemongo.bson.BSONBinary

import lila.db.BSON.BSONJodaDateTimeHandler
Expand Down Expand Up @@ -86,15 +86,13 @@ object GameRepo {

def cursor(
selector: Bdoc,
readPreference: ReadPreference = ReadPreference.secondaryPreferred)(
implicit cp: CursorProducer[Game]) =
readPreference: ReadPreference = ReadPreference.secondaryPreferred) =
coll.find(selector).cursor[Game](readPreference)

def sortedCursor(
selector: Bdoc,
sort: Bdoc,
readPreference: ReadPreference = ReadPreference.secondaryPreferred)(
implicit cp: CursorProducer[Game]) =
readPreference: ReadPreference = ReadPreference.secondaryPreferred) =
coll.find(selector).sort(sort).cursor[Game](readPreference)

def unrate(gameId: String) =
Expand Down Expand Up @@ -364,7 +362,7 @@ object GameRepo {
Project($doc(
F.playerUids -> true,
F.id -> false)),
UnwindField(F.playerUids),
Unwind(F.playerUids),
Match($doc(F.playerUids -> $doc("$ne" -> userId))),
GroupField(F.playerUids)("gs" -> SumValue(1)),
Sort(Descending("gs")),
Expand Down Expand Up @@ -433,15 +431,15 @@ object GameRepo {
Match,
Sort,
SumValue,
UnwindField
Unwind
}

coll.aggregate(Match($doc(
F.createdAt $gt since,
F.status $gte chess.Status.Mate.id,
s"${F.playerUids}.0" $exists true
)), List(
UnwindField(F.playerUids),
Unwind(F.playerUids),
Match($doc(
F.playerUids -> $doc("$ne" -> "")
)),
Expand Down
4 changes: 1 addition & 3 deletions modules/gameSearch/src/main/GameSearchApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ final class GameSearchApi(client: ESClient) extends SearchReadApi[Game, Query] {
import lila.db.BSON.BSONJodaDateTimeHandler
import reactivemongo.api._
import reactivemongo.bson._
import reactivemongo.play.iteratees.cursorProducer

var nbSkipped = 0
val batchSize = 1000
val maxGames = Int.MaxValue
Expand All @@ -111,7 +109,7 @@ final class GameSearchApi(client: ESClient) extends SearchReadApi[Game, Query] {
selector = $doc("ca" $gt since),
sort = $doc("ca" -> 1),
readPreference = ReadPreference.secondaryPreferred)
.enumerator(maxGames) &>
.enumerate(maxGames, stopOnError = true) &>
Enumeratee.grouped(Iteratee takeUpTo batchSize) |>>>
Enumeratee.mapM[Seq[Game]].apply[(Seq[Game], Set[String])] { games =>
GameRepo filterAnalysed games.map(_.id) map games.->
Expand Down
2 changes: 1 addition & 1 deletion modules/history/src/main/History.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object History {

private[history] implicit val RatingsMapReader = new BSONDocumentReader[RatingsMap] {
def read(doc: BSONDocument): RatingsMap = doc.stream.flatMap {
case scala.util.Success(BSONElement(k, BSONInteger(v))) => parseIntOption(k) map (_ -> v)
case scala.util.Success((k, BSONInteger(v))) => parseIntOption(k) map (_ -> v)
case _ => none[(Int, Int)]
}.toList sortBy (_._1)
}
Expand Down
2 changes: 1 addition & 1 deletion modules/history/src/main/HistoryApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ final class HistoryApi(coll: Coll) {
coll.update(
$id(user.id),
$doc("$set" -> $doc(changes.map {
case (perf, rating) => BSONElement(s"$perf.$days", $int(rating))
case (perf, rating) => s"$perf.$days" -> $int(rating)
})),
upsert = true
).void
Expand Down
22 changes: 11 additions & 11 deletions modules/insight/src/main/AggregationPipeline.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,26 @@ private final class AggregationPipeline {
private val sampleGames = Sample(10 * 1000)
private val sortDate = Sort(Descending(F.date))
private val sampleMoves = Sample(200 * 1000).some
private val unwindMoves = UnwindField(F.moves).some
private val unwindMoves = Unwind(F.moves).some
private val sortNb = Sort(Descending("nb")).some
private def limit(nb: Int) = Limit(nb).some
private def group(d: Dimension[_], f: GroupFunction) = Group(dimensionGroupId(d))(
"v" -> f,
"nb" -> SumValue(1),
"ids" -> AddFieldToSet("_id")
"ids" -> AddToSet("_id")
).some
private def groupMulti(d: Dimension[_], metricDbKey: String) = Group($doc(
"dimension" -> dimensionGroupId(d),
"metric" -> ("$" + metricDbKey)))(
"v" -> SumValue(1),
"ids" -> AddFieldToSet("_id")
"ids" -> AddToSet("_id")
).some
private val regroupStacked = GroupField("_id.dimension")(
"nb" -> SumField("v"),
"ids" -> FirstField("ids"),
"stack" -> Push(BSONDocument(
"ids" -> First("ids"),
"stack" -> PushMulti(
"metric" -> "_id.metric",
"v" -> "v"))).some
"v" -> "v")).some
private val sliceIds = Project($doc(
"_id" -> true,
"v" -> true,
Expand All @@ -82,7 +82,7 @@ private final class AggregationPipeline {
combineDocs(extraMatcher :: question.filters.collect {
case f if f.dimension.isInMove => f.matcher
}).some.filterNot(_.isEmpty) map Match
def projectForMove = Project(BSONDocument({
def projectForMove = Project($doc({
metric.dbKey :: dimension.dbKey :: filters.collect {
case Filter(d, _) if d.isInMove => d.dbKey
}
Expand All @@ -104,15 +104,15 @@ private final class AggregationPipeline {
unwindMoves,
matchMoves(),
sampleMoves,
group(dimension, AvgField(F.moves("c"))),
group(dimension, Avg(F.moves("c"))),
sliceIds
)
case M.Material => List(
projectForMove,
unwindMoves,
matchMoves(),
sampleMoves,
group(dimension, AvgField(F.moves("i"))),
group(dimension, Avg(F.moves("i"))),
sliceIds
)
case M.Opportunism => List(
Expand Down Expand Up @@ -177,11 +177,11 @@ private final class AggregationPipeline {
sliceIds
)
case M.RatingDiff => List(
group(dimension, AvgField(F.ratingDiff)),
group(dimension, Avg(F.ratingDiff)),
sliceIds
)
case M.OpponentRating => List(
group(dimension, AvgField(F.opponentRating)),
group(dimension, Avg(F.opponentRating)),
sliceIds
)
case M.Result => List(
Expand Down
Loading

0 comments on commit b821d8f

Please sign in to comment.