From 439f74ec29ac35b46f242b5855023a27f06d1435 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Fri, 26 Oct 2012 01:32:30 +0200 Subject: [PATCH] optimize player and watcher pages performances --- app/controllers/Round.scala | 13 ++++--------- app/user/UserRepo.scala | 7 ++----- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/app/controllers/Round.scala b/app/controllers/Round.scala index 4f404e7c2a..5a35bea1f3 100644 --- a/app/controllers/Round.scala +++ b/app/controllers/Round.scala @@ -56,10 +56,8 @@ object Round extends LilaController with TheftPrevention with RoundEventPerforme pov.game.started.fold( for { roomHtml ← messenger render pov.game - bookmarkers ← bookmarkApi usersByGame pov.game - engine ← pov.opponent.userId.fold( - u ⇒ userRepo isEngine u, - io(false)) + bookmarkers ← pov.game.hasBookmarks.fold(bookmarkApi usersByGame pov.game, io(Nil)) + engine ← pov.opponent.userId.fold(userRepo.isEngine, io(false)) analysed ← analyser has pov.gameId tour ← tournamentRepo byId pov.game.tournamentId } yield PreventTheft(pov) { @@ -67,7 +65,7 @@ object Round extends LilaController with TheftPrevention with RoundEventPerforme pov, version(pov.gameId), engine, - roomHtml map { Html(_) }, + roomHtml map Html.apply, bookmarkers, analysed, tour = tour)) @@ -90,10 +88,7 @@ object Round extends LilaController with TheftPrevention with RoundEventPerforme } private def watch(pov: Pov)(implicit ctx: Context): IO[Result] = for { - bookmarkers ← pov.game.hasBookmarks.fold( - bookmarkApi usersByGame pov.game, - io(Nil) - ) + bookmarkers ← pov.game.hasBookmarks.fold(bookmarkApi usersByGame pov.game, io(Nil)) roomHtml ← messenger renderWatcher pov.game analysed ← analyser has pov.gameId tour ← tournamentRepo byId pov.game.tournamentId diff --git a/app/user/UserRepo.scala b/app/user/UserRepo.scala index c9c763e689..e3eb0d898c 100644 --- a/app/user/UserRepo.scala +++ b/app/user/UserRepo.scala @@ -168,11 +168,8 @@ class UserRepo(collection: MongoCollection) } def isEngine(username: String): IO[Boolean] = io { - for { - obj ← collection.findOne(byIdQuery(username), DBObject("engine" -> true)) - engine ← obj.getAs[Boolean]("engine") - } yield engine - } map (_ | false) + collection.find(byIdQuery(username) ++ DBObject("engine" -> true)).size != 0 + } def setBio(user: User, bio: String) = updateIO(user)($set("bio" -> bio))