Revert "fix user average elo counter using mongodb aggregation"

This reverts commit 260b51be90.
This commit is contained in:
Thibault Duplessis 2013-05-28 18:26:41 +02:00
parent 95b3c18928
commit 4bd8142736
2 changed files with 15 additions and 15 deletions

View file

@ -76,7 +76,7 @@ object UserRepo {
$update($select(id), $set(("settings." + key) -> value))
def getSetting(id: ID, key: String): Fu[Option[String]] =
$primitive.one($select(id), "settings") {
$primitive.one($select(id), "settings") {
_.asOpt[Map[String, String]] flatMap (_ get key)
}
@ -149,18 +149,20 @@ object UserRepo {
}
def idsAverageElo(ids: Iterable[String]): Fu[Int] = {
import reactivemongo.bson._
import reactivemongo.core.commands._
val command = Aggregate(userTube.coll.name, Seq(
Match(BSONDocument("_id" -> BSONDocument("$in" -> BSONArray(
ids map { id BSONString(id) }
)))),
Group(BSONBoolean(true))("elo" -> SumField("$elo"))
))
userTube.coll.db.command(command) map { stream
(stream.toList.headOption map { obj
toJSON(obj).asOpt[JsObject] flatMap { _ int "elo" }
}).flatten
val command = MapReduce(
collectionName = userTube.coll.name,
mapFunction = """function() { emit("e", this.elo); }""",
reduceFunction = """function(key, values) {
var sum = 0;
for(var i in values) { sum += values[i]; }
return Math.round(sum / values.length);
}""",
query = Some {
JsObjectWriter write Json.obj("_id" -> $in(ids map normalize))
}
)
userTube.coll.db.command(command) map { res
toJSON(res).arr("results").flatMap(_.apply(0) int "value")
} map (~_)
}

2
todo
View file

@ -72,8 +72,6 @@ check team average elo http://en.lichess.org/inbox/benuegti#bottom
DEPLOY p21
----------
wait for reactivemongo fix https://github.com/zenexity/ReactiveMongo/pull/81
upgrade nginx to get websocket proxying support
upgrade elasticsearch to 0.90
wait for https://github.com/zenexity/ReactiveMongo/issues/72