bypass json during user (de)serialization - WIP
This commit is contained in:
parent
8842699953
commit
8205253cda
|
@ -16,6 +16,9 @@ private[user] case class Count(
|
|||
|
||||
private[user] object Count {
|
||||
|
||||
import reactivemongo.bson.Macros
|
||||
private[user] lazy val bsTube = lila.db.BsTube(Macros.handler[Count])
|
||||
|
||||
import lila.db.JsTube
|
||||
import play.api.libs.json.Json
|
||||
|
||||
|
|
|
@ -27,6 +27,9 @@ object Profile {
|
|||
|
||||
val default = Profile()
|
||||
|
||||
import reactivemongo.bson.Macros
|
||||
private[user] lazy val bsTube = lila.db.BsTube(Macros.handler[Profile])
|
||||
|
||||
import lila.db.JsTube
|
||||
import play.api.libs.json._
|
||||
|
||||
|
|
|
@ -51,6 +51,10 @@ object SpeedElos {
|
|||
SubElo.default,
|
||||
SubElo.default)
|
||||
|
||||
import reactivemongo.bson.Macros
|
||||
private implicit def subEloBsTube = SubElo.bsTube.handler
|
||||
private[user] lazy val bsTube = lila.db.BsTube(Macros.handler[SpeedElos])
|
||||
|
||||
private implicit def subEloTube = SubElo.tube
|
||||
|
||||
private[user] lazy val tube = JsTube[SpeedElos](
|
||||
|
|
|
@ -16,6 +16,9 @@ case object SubElo {
|
|||
|
||||
val default = SubElo(0, User.STARTING_ELO)
|
||||
|
||||
import reactivemongo.bson.Macros
|
||||
private[user] lazy val bsTube = lila.db.BsTube(Macros.handler[SubElo])
|
||||
|
||||
private[user] lazy val tube = JsTube[SubElo](Json.reads[SubElo], Json.writes[SubElo])
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package lila.user
|
||||
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import chess.Speed
|
||||
import org.joda.time.DateTime
|
||||
import scala.concurrent.duration._
|
||||
|
||||
case class User(
|
||||
id: String,
|
||||
|
@ -61,6 +62,75 @@ object User {
|
|||
|
||||
case class Active(user: User, lang: String)
|
||||
|
||||
object BSONFields {
|
||||
val id = "_id"
|
||||
val username = "username"
|
||||
val elo = "elo"
|
||||
val speedElos = "speedElos"
|
||||
val variantElos = "variantElos"
|
||||
val count = "count"
|
||||
val troll = "troll"
|
||||
val ipBan = "ipBan"
|
||||
val enabled = "enabled"
|
||||
val roles = "roles"
|
||||
val profile = "profile"
|
||||
val engine = "engine"
|
||||
val toints = "toints"
|
||||
val createdAt = "createdAt"
|
||||
val seenAt = "seenAt"
|
||||
val lang = "lang"
|
||||
}
|
||||
|
||||
import reactivemongo.bson.{ Macros, BSONDocument }
|
||||
import lila.db.BSON
|
||||
import lila.db.BSON.BSONJodaDateTimeHandler
|
||||
private implicit def countBsTube = Count.bsTube.handler
|
||||
private implicit def speedElosBsTube = SpeedElos.bsTube.handler
|
||||
private implicit def variantElosBsTube = VariantElos.bsTube.handler
|
||||
private implicit def profileBsTube = Profile.bsTube.handler
|
||||
private[user] lazy val bsTube = lila.db.BsTube(Macros.handler[User])
|
||||
|
||||
implicit val userBSONHandler = new BSON[User] {
|
||||
|
||||
import BSONFields._
|
||||
|
||||
def reads(r: BSON.Reader): User = User(
|
||||
id = r str id,
|
||||
username = r str username,
|
||||
elo = r int elo,
|
||||
speedElos = r.getO[SpeedElos](speedElos) | SpeedElos.default,
|
||||
variantElos = r.getO[VariantElos](variantElos) | VariantElos.default,
|
||||
count = r.get[Count](count),
|
||||
troll = r boolD troll,
|
||||
ipBan = r boolD ipBan,
|
||||
enabled = r bool enabled,
|
||||
roles = ~r.getO[List[String]](roles),
|
||||
profile = r.getO[Profile](profile),
|
||||
engine = r boolD engine,
|
||||
toints = r intD toints,
|
||||
createdAt = r date createdAt,
|
||||
seenAt = r dateO seenAt,
|
||||
lang = r strO lang)
|
||||
|
||||
def writes(w: BSON.Writer, o: User) = BSONDocument(
|
||||
id -> o.id,
|
||||
username -> o.username,
|
||||
elo -> o.elo,
|
||||
speedElos -> o.speedElos,
|
||||
variantElos -> o.variantElos,
|
||||
count -> o.count,
|
||||
troll -> w.boolO(o.troll),
|
||||
ipBan -> w.boolO(o.ipBan),
|
||||
enabled -> o.enabled,
|
||||
roles -> o.roles.some.filter(_.nonEmpty),
|
||||
profile -> o.profile,
|
||||
engine -> w.boolO(o.engine),
|
||||
toints -> w.intO(o.toints),
|
||||
createdAt -> o.createdAt,
|
||||
seenAt -> o.seenAt,
|
||||
lang -> o.lang)
|
||||
}
|
||||
|
||||
import lila.db.JsTube
|
||||
import JsTube.Helpers._
|
||||
import play.api.libs.json._
|
||||
|
|
|
@ -44,6 +44,10 @@ object VariantElos {
|
|||
|
||||
val default = VariantElos(SubElo.default, SubElo.default)
|
||||
|
||||
import reactivemongo.bson.Macros
|
||||
private implicit def subEloBsTube = SubElo.bsTube.handler
|
||||
private[user] lazy val bsTube = lila.db.BsTube(Macros.handler[VariantElos])
|
||||
|
||||
private implicit def subEloTube = SubElo.tube
|
||||
|
||||
private[user] lazy val tube = JsTube[VariantElos](
|
||||
|
|
Loading…
Reference in a new issue