Skip to content

Commit

Permalink
fix many reactivemongo deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jul 14, 2015
1 parent f335941 commit 7cd7f9b
Show file tree
Hide file tree
Showing 34 changed files with 73 additions and 78 deletions.
2 changes: 1 addition & 1 deletion modules/db/src/main/PaginatorAdapter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ final class BSONAdapter[A: BSONDocumentReader](
collection.find(selector, projection)
.sort(sort)
.copy(options = QueryOpts(skipN = offset))
.cursor[A]
.cursor[A]()
.collect[List](length)
}
2 changes: 1 addition & 1 deletion modules/db/src/main/api/cursor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ object $cursor {
apply($query(q))

def apply[A: TubeInColl](b: QueryBuilder): Cursor[Option[A]] =
b.cursor[Option[A]]
b.cursor[Option[A]]()
}
8 changes: 4 additions & 4 deletions modules/db/src/main/api/enumerate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ import lila.db.Implicits._
object $enumerate {

def apply[A: BSONDocumentReader](query: QueryBuilder, limit: Int = Int.MaxValue)(op: A => Any): Funit =
query.cursor[A].enumerate(limit) run {
query.cursor[A]().enumerate(limit) run {
Iteratee.foreach((obj: A) => op(obj))
}

def over[A: TubeInColl](query: QueryBuilder, limit: Int = Int.MaxValue)(op: A => Funit): Funit =
query.cursor[Option[A]].enumerate(limit, false) run {
query.cursor[Option[A]]().enumerate(limit, false) run {
Iteratee.foldM(()) {
case (_, Some(obj)) => op(obj)
case _ => funit
}
}

def bulk[A: BSONDocumentReader](query: QueryBuilder, size: Int, limit: Int = Int.MaxValue)(op: List[A] => Funit): Funit =
query.batch(size).cursor[A].enumerateBulks(limit) run {
query.batch(size).cursor[A]().enumerateBulks(limit) run {
Iteratee.foldM(()) {
case (_, objs) => op(objs.toList)
}
}

def fold[A: BSONDocumentReader, B](query: QueryBuilder)(zero: B)(f: (B, A) => B): Fu[B] =
query.cursor[A].enumerate() |>>> Iteratee.fold(zero)(f)
query.cursor[A]().enumerate() |>>> Iteratee.fold(zero)(f)

def foldMonoid[A: BSONDocumentReader, B: Monoid](query: QueryBuilder)(f: A => B): Fu[B] =
fold[A, B](query)(Monoid[B].zero) { case (b, a) => f(a) |+| b }
Expand Down
5 changes: 0 additions & 5 deletions modules/db/src/main/api/find.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,4 @@ object $find {

def apply[A: TubeInColl](b: QueryBuilder, nb: Int): Fu[List[A]] =
b.toList[Option[A]](nb.some) map (_.flatten)

// useful in capped collections
// def recent[A: TubeInColl](max: Int): Fu[List[A]] = (
// pimpQB($query.all).sort($sort.naturalOrder)
// ).cursor[Option[A]] toList max map (_.flatten)
}
4 changes: 2 additions & 2 deletions modules/db/src/main/typesAndImplicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ trait Implicits extends Types {
def batch(nb: Int): QueryBuilder = b.options(b.options batchSize nb)

def toList[A: BSONDocumentReader](limit: Option[Int]): Fu[List[A]] =
limit.fold(b.cursor[A].collect[List]()) { l =>
batch(l).cursor[A].collect[List](l)
limit.fold(b.cursor[A]().collect[List]()) { l =>
batch(l).cursor[A]().collect[List](l)
}

def toListFlatten[A: Tube](limit: Option[Int]): Fu[List[A]] =
Expand Down
8 changes: 4 additions & 4 deletions modules/donation/src/main/DonationApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ final class DonationApi(coll: Coll, monthlyGoal: Int) {

def list(nb: Int) = coll.find(decentAmount)
.sort(BSONDocument("date" -> -1))
.cursor[Donation]
.cursor[Donation]()
.collect[List](nb)

def top(nb: Int) = coll.find(BSONDocument(
"userId" -> BSONDocument("$exists" -> true)
)).sort(BSONDocument(
"gross" -> -1,
"date" -> -1
)).cursor[Donation]
)).cursor[Donation]()
.collect[List](nb)

def create(donation: Donation) = coll insert donation recover {
Expand All @@ -34,7 +34,7 @@ final class DonationApi(coll: Coll, monthlyGoal: Int) {
coll.find(
decentAmount ++ BSONDocument("userId" -> userId),
BSONDocument("net" -> true, "_id" -> false)
).cursor[BSONDocument].collect[List]() map2 { (obj: BSONDocument) =>
).cursor[BSONDocument]().collect[List]() map2 { (obj: BSONDocument) =>
~obj.getAs[Int]("net")
} map (_.sum)

Expand All @@ -47,7 +47,7 @@ final class DonationApi(coll: Coll, monthlyGoal: Int) {
"$lt" -> to
)),
BSONDocument("net" -> true, "_id" -> false)
).cursor[BSONDocument].collect[List]() map2 { (obj: BSONDocument) =>
).cursor[BSONDocument]().collect[List]() map2 { (obj: BSONDocument) =>
~obj.getAs[Int]("net")
} map (_.sum) map { amount =>
Progress(from, monthlyGoal, amount)
Expand Down
2 changes: 1 addition & 1 deletion modules/game/src/main/CrosstableApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ final class CrosstableApi(coll: Coll) {
selector,
BSONDocument(Game.BSONFields.winnerId -> true)
).sort(BSONDocument(Game.BSONFields.createdAt -> -1))
.cursor[BSONDocument].collect[List](maxGames).map {
.cursor[BSONDocument]().collect[List](maxGames).map {
_.map { doc =>
doc.getAs[String](Game.BSONFields.id).map { id =>
Result(id, doc.getAs[String](Game.BSONFields.winnerId))
Expand Down
2 changes: 1 addition & 1 deletion modules/game/src/main/GameRepo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ object GameRepo {

def associatePgn(ids: Seq[ID]): Fu[Map[String, PgnMoves]] =
gameTube.coll.find($select byIds ids)
.cursor[BSONDocument]
.cursor[BSONDocument]()
.collect[List]() map2 { (obj: BSONDocument) =>
extractPgnMoves(obj) flatMap { moves =>
obj.getAs[String]("_id") map (_ -> moves)
Expand Down
2 changes: 1 addition & 1 deletion modules/game/src/main/PlayTime.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ object PlayTime {
moveTimeField -> true,
tvField -> true
))
.cursor[BSONDocument]
.cursor[BSONDocument]()
.enumerate() |>>> (Iteratee.fold(User.PlayTime(0, 0)) {
case (pt, doc) =>
val t = doc.getAs[ByteArray](moveTimeField) ?? { times =>
Expand Down
4 changes: 2 additions & 2 deletions modules/lobby/src/main/SeekApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class SeekApi(
private def allCursor =
coll.find(BSONDocument())
.sort(BSONDocument("createdAt" -> -1))
.cursor[Seek]
.cursor[Seek]()

private val cache = AsyncCache[CacheKey, List[Seek]](
f = {
Expand Down Expand Up @@ -69,7 +69,7 @@ final class SeekApi(
def findByUser(userId: String): Fu[List[Seek]] =
coll.find(BSONDocument("user.id" -> userId))
.sort(BSONDocument("createdAt" -> -1))
.cursor[Seek].collect[List]()
.cursor[Seek]().collect[List]()

def remove(seek: Seek) =
coll.remove(BSONDocument("_id" -> seek.id)).void >> cache.clear
Expand Down
2 changes: 1 addition & 1 deletion modules/mod/src/main/AssessApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class AssessApi(
def getPlayerAssessmentsByUserId(userId: String, nb: Int = 100) =
collAssessments.find(BSONDocument("userId" -> userId))
.sort(BSONDocument("date" -> -1))
.cursor[PlayerAssessment]
.cursor[PlayerAssessment]()
.collect[List](nb)

def getResultsByGameIdAndColor(gameId: String, color: Color) =
Expand Down
2 changes: 1 addition & 1 deletion modules/opening/src/main/UserInfos.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object UserInfos {
Attempt.BSONFields.userId -> userId
)).sort(BSONDocument(
Attempt.BSONFields.date -> -1
)).cursor[Attempt].collect[List](math.max(historySize, chartSize))
)).cursor[Attempt]().collect[List](math.max(historySize, chartSize))
}

private def makeHistory(attempts: List[Attempt]) = attempts.take(historySize)
Expand Down
2 changes: 1 addition & 1 deletion modules/playban/src/main/PlaybanApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ final class PlaybanApi(
def bans(userIds: List[String]): Fu[Map[String, Int]] = coll.find(
BSONDocument("_id" -> BSONDocument("$in" -> userIds)),
BSONDocument("b" -> true)
).cursor[BSONDocument].collect[List]().map {
).cursor[BSONDocument]().collect[List]().map {
_.flatMap { obj =>
obj.getAs[String]("_id") flatMap { id =>
obj.getAs[BSONArray]("b") map { id -> _.stream.size }
Expand Down
2 changes: 1 addition & 1 deletion modules/pref/src/main/PrefApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ final class PrefApi(
coll.find(BSONDocument(
"_id" -> BSONDocument("$in" -> userIds),
"follow" -> false
), BSONDocument("_id" -> true)).cursor[BSONDocument].collect[List]() map {
), BSONDocument("_id" -> true)).cursor[BSONDocument]().collect[List]() map {
_.flatMap(_.getAs[String]("_id")).toSet
}

Expand Down
6 changes: 3 additions & 3 deletions modules/puzzle/src/main/PuzzleApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private[puzzle] final class PuzzleApi(
def latest(nb: Int): Fu[List[Puzzle]] =
puzzleColl.find(BSONDocument())
.sort(BSONDocument("date" -> -1))
.cursor[Puzzle]
.cursor[Puzzle]()
.collect[List](nb)

def importBatch(json: JsValue, token: String): Fu[List[Try[PuzzleId]]] =
Expand Down Expand Up @@ -57,7 +57,7 @@ private[puzzle] final class PuzzleApi(
def export(nb: Int): Fu[List[Puzzle]] = List(true, false).map { mate =>
puzzleColl.find(BSONDocument("mate" -> mate))
.sort(BSONDocument(Puzzle.BSONFields.voteSum -> -1))
.cursor[Puzzle].collect[List](nb / 2)
.cursor[Puzzle]().collect[List](nb / 2)
}.sequenceFu.map(_.flatten)
}

Expand Down Expand Up @@ -112,7 +112,7 @@ private[puzzle] final class PuzzleApi(
Attempt.BSONFields.vote -> true,
Attempt.BSONFields.id -> false
)).sort(BSONDocument(Attempt.BSONFields.date -> -1))
.cursor[BSONDocument]
.cursor[BSONDocument]()
.collect[List](5) map {
case attempts if attempts.size < 5 => true
case attempts => attempts.foldLeft(false) {
Expand Down
2 changes: 1 addition & 1 deletion modules/puzzle/src/main/UserInfos.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ object UserInfos {
Attempt.BSONFields.userId -> userId
)).sort(BSONDocument(
Attempt.BSONFields.date -> -1
)).cursor[Attempt]
)).cursor[Attempt]()
.collect[List](math.max(historySize, chartSize))
}

Expand Down
10 changes: 5 additions & 5 deletions modules/qa/src/main/QaApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ final class QaApi(
questionColl.find(BSONDocument("_id" -> id)).one[Question]

def findByIds(ids: List[QuestionId]): Fu[List[Question]] =
questionColl.find(BSONDocument("_id" -> BSONDocument("$in" -> ids.distinct))).cursor[Question].collect[List]()
questionColl.find(BSONDocument("_id" -> BSONDocument("$in" -> ids.distinct))).cursor[Question]().collect[List]()

def accept(q: Question) = questionColl.update(
BSONDocument("_id" -> q.id),
Expand All @@ -88,18 +88,18 @@ final class QaApi(
prefix = "qa:popular",
f = (nb: Int) => questionColl.find(BSONDocument())
.sort(BSONDocument("vote.score" -> -1))
.cursor[Question].collect[List](nb),
.cursor[Question]().collect[List](nb),
timeToLive = 3 hour)

def popular(max: Int): Fu[List[Question]] = popularCache(max)

def byTag(tag: String, max: Int): Fu[List[Question]] =
questionColl.find(BSONDocument("tags" -> tag.toLowerCase))
.sort(BSONDocument("vote.score" -> -1))
.cursor[Question].collect[List](max)
.cursor[Question]().collect[List](max)

def byTags(tags: List[String], max: Int): Fu[List[Question]] =
questionColl.find(BSONDocument("tags" -> BSONDocument("$in" -> tags.map(_.toLowerCase)))).cursor[Question].collect[List](max)
questionColl.find(BSONDocument("tags" -> BSONDocument("$in" -> tags.map(_.toLowerCase)))).cursor[Question]().collect[List](max)

def addComment(c: Comment)(q: Question) = questionColl.update(
BSONDocument("_id" -> q.id),
Expand Down Expand Up @@ -191,7 +191,7 @@ final class QaApi(
def popular(questionId: QuestionId): Fu[List[Answer]] =
answerColl.find(BSONDocument("questionId" -> questionId))
.sort(BSONDocument("vote.score" -> -1))
.cursor[Answer].collect[List]()
.cursor[Answer]().collect[List]()

def zipWithQuestions(answers: List[Answer]): Fu[List[AnswerWithQuestion]] =
question.findByIds(answers.map(_.questionId)) map { qs =>
Expand Down
2 changes: 1 addition & 1 deletion modules/qa/src/main/Search.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ final class Search(collection: Coll) {
def apply(q: String): Fu[List[Question]] =
collection.find(BSONDocument(
"$text" -> BSONDocument("$search" -> q)
)).cursor[Question].collect[List]()
)).cursor[Question]().collect[List]()
}

2 changes: 1 addition & 1 deletion modules/relay/src/main/ContentApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class ContentApi(coll: Coll) {

def byIds(ids: Seq[String]): Fu[List[Content]] = coll.find(
BSONDocument("_id" -> BSONDocument("$in" -> ids))
).cursor[Content].collect[List]()
).cursor[Content]().collect[List]()

def byRelays(relays: Seq[Relay]): Fu[List[Content]] = byIds(relays.map(Content.mkId).distinct)

Expand Down
8 changes: 4 additions & 4 deletions modules/relay/src/main/RelayRepo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ final class RelayRepo(coll: Coll) {
def recentByName(name: String): Fu[Option[Relay]] =
coll.find(selectEnabled ++ selectName(name) ++ selectRecent).one[Relay]

def started: Fu[List[Relay]] = coll.find(selectStarted).cursor[Relay].collect[List]()
def started: Fu[List[Relay]] = coll.find(selectStarted).cursor[Relay]().collect[List]()

def startedTopRated(nb: Int): Fu[List[Relay]] =
coll.find(selectEnabledStarted).sort(sortElo).cursor[Relay].collect[List](nb)
coll.find(selectEnabledStarted).sort(sortElo).cursor[Relay]().collect[List](nb)

def recent(nb: Int): Fu[List[Relay]] =
coll.find(BSONDocument()).sort(sortRecent).cursor[Relay].collect[List](nb)
coll.find(BSONDocument()).sort(sortRecent).cursor[Relay]().collect[List](nb)

def exists(id: String): Fu[Boolean] = coll.count(selectId(id).some) map (0 !=)

def withGamesButNoElo: Fu[List[Relay]] =
coll.find(selectStarted ++ BSONDocument(
"elo" -> BSONDocument("$exists" -> false),
"games.0" -> BSONDocument("$exists" -> true)
)).cursor[Relay].collect[List]()
)).cursor[Relay]().collect[List]()

def setElo(id: String, elo: Int) = coll.update(
selectId(id),
Expand Down
2 changes: 1 addition & 1 deletion modules/security/src/main/Api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private[security] final class Api(firewall: Firewall, tor: Tor) {
tube.storeColl.find(
BSONDocument("user" -> userId),
BSONDocument("ip" -> true)
).cursor[BSONDocument].collect[List]().map {
).cursor[BSONDocument]().collect[List]().map {
_.flatMap(_.getAs[String]("ip"))
}.flatMap { ips =>
tube.storeColl.find(
Expand Down
2 changes: 1 addition & 1 deletion modules/security/src/main/Store.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ object Store {
storeColl.find(
BSONDocument("user" -> userId),
BSONDocument("ip" -> true, "ua" -> true, "tor" -> true)
).cursor[Info].collect[List]()
).cursor[Info]().collect[List]()
}
4 changes: 2 additions & 2 deletions modules/security/src/main/UserSpy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object UserSpy {
"ip" -> BSONDocument("$nin" -> ips)
),
BSONDocument("ip" -> true)
).cursor[BSONDocument].collect[List]() map {
).cursor[BSONDocument]().collect[List]() map {
_.flatMap(_.getAs[IP]("ip")).toSet
}
}
Expand All @@ -76,7 +76,7 @@ object UserSpy {
"user" -> BSONDocument("$nin" -> users.map(_.id))
),
BSONDocument("user" -> true)
).cursor[BSONDocument].collect[List]() map {
).cursor[BSONDocument]().collect[List]() map {
_.flatMap(_.getAs[String]("user"))
} flatMap { userIds =>
userIds.nonEmpty ?? (UserRepo byIds userIds.distinct) map (_.toSet)
Expand Down
14 changes: 7 additions & 7 deletions modules/simul/src/main/SimulRepo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ private[simul] final class SimulRepo(simulColl: Coll) {
simulColl.find(BSONDocument("_id" -> id)).one[Simul]

def exists(id: Simul.ID): Fu[Boolean] =
simulColl.db command Count(simulColl.name, BSONDocument("_id" -> id).some) map (0 !=)
simulColl.count(BSONDocument("_id" -> id).some) map (0 !=)

def createdByHostId(hostId: String): Fu[List[Simul]] =
simulColl.find(createdSelect ++ BSONDocument("hostId" -> hostId))
.cursor[Simul].collect[List]()
.cursor[Simul]().collect[List]()

def findStarted(id: Simul.ID): Fu[Option[Simul]] =
find(id) map (_ filter (_.isStarted))
Expand All @@ -55,27 +55,27 @@ private[simul] final class SimulRepo(simulColl: Coll) {

def allCreated: Fu[List[Simul]] = simulColl.find(
createdSelect
).sort(createdSort).cursor[Simul].collect[List]()
).sort(createdSort).cursor[Simul]().collect[List]()

def allCreatedFeaturable: Fu[List[Simul]] = simulColl.find(
createdSelect ++ BSONDocument(
"createdAt" -> BSONDocument("$gte" -> DateTime.now.minusMinutes(15)),
"hostRating" -> BSONDocument("$gte" -> 1700)
)
).sort(createdSort).cursor[Simul].collect[List]()
).sort(createdSort).cursor[Simul]().collect[List]()

def allStarted: Fu[List[Simul]] = simulColl.find(
startedSelect
).sort(createdSort).cursor[Simul].collect[List]()
).sort(createdSort).cursor[Simul]().collect[List]()

def allFinished(max: Int): Fu[List[Simul]] = simulColl.find(
finishedSelect
).sort(createdSort).cursor[Simul].collect[List](max)
).sort(createdSort).cursor[Simul]().collect[List](max)

def allNotFinished =
simulColl.find(
BSONDocument("status" -> BSONDocument("$ne" -> SimulStatus.Finished.id))
).cursor[Simul].collect[List]()
).cursor[Simul]().collect[List]()

def create(simul: Simul): Funit =
simulColl insert simul void
Expand Down
Loading

0 comments on commit 7cd7f9b

Please sign in to comment.