load less users from db

pull/83/head
Thibault Duplessis 2012-10-28 19:30:54 +01:00
parent 7d03608627
commit d88a9f549e
10 changed files with 18 additions and 19 deletions

View File

@ -30,11 +30,8 @@ final class BookmarkApi(
def countByUser(user: User): Int =
cached.count(user.id)
def usersByGame(game: DbGame): IO[List[User]] =
if (game.hasBookmarks) for {
userIds bookmarkRepo userIdsByGameId game.id
users (userIds map userRepo.byId).sequence
} yield users.flatten
def userIdsByGame(game: DbGame): IO[List[String]] =
if (game.hasBookmarks) bookmarkRepo userIdsByGameId game.id
else io(Nil)
def removeByGame(game: DbGame): IO[Unit] =

View File

@ -40,7 +40,7 @@ object Analyse extends LilaController {
IOptionIOk(gameRepo.pov(id, color)) { pov
for {
roomHtml roundMessenger renderWatcher pov.game
bookmarkers bookmarkApi usersByGame pov.game
bookmarkers bookmarkApi userIdsByGame pov.game
pgnString pgnRepo get id
pgn pgnDump(pov.game, pgnString)
analysis analyser get pov.game.id

View File

@ -55,7 +55,7 @@ object Round extends LilaController with TheftPrevention with RoundEventPerforme
pov.game.started.fold(
for {
roomHtml messenger render pov.game
bookmarkers pov.game.hasBookmarks.fold(bookmarkApi usersByGame pov.game, io(Nil))
bookmarkers bookmarkApi userIdsByGame pov.game
engine pov.opponent.userId.fold(userRepo.isEngine, io(false))
analysed analyser has pov.gameId
tour tournamentRepo byId pov.game.tournamentId
@ -87,7 +87,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 bookmarkApi userIdsByGame pov.game
roomHtml messenger renderWatcher pov.game
analysed analyser has pov.gameId
tour tournamentRepo byId pov.game.tournamentId

View File

@ -12,7 +12,7 @@ final class Cached(
import Cached._
def username(userId: String) =
def username(userId: String): Option[String] =
usernameCache.getOrElseUpdate(
userId.toLowerCase,
(userRepo username userId).unsafePerformIO

View File

@ -41,6 +41,13 @@ trait UserHelper {
userId: String,
cssClass: Option[String]): Html = userIdLink(userId.some, cssClass)
def userIdLinkMini(userId: String) = Html {
"""<a href="%s">%s</a>""".format(
routes.User.show(userId),
(cached username userId) | userId
)
}
def userLink(
user: User,
cssClass: Option[String] = None,

View File

@ -1,4 +1,4 @@
@(pov: Pov, pgn: String, roomHtml: Html, bookmarkers: List[User], opening: Option[chess.OpeningExplorer.Opening], analysis: Option[lila.analyse.Analysis], version: Int, tour: Option[lila.tournament.Tournament])(implicit ctx: Context)
@(pov: Pov, pgn: String, roomHtml: Html, bookmarkers: List[String], opening: Option[chess.OpeningExplorer.Opening], analysis: Option[lila.analyse.Analysis], version: Int, tour: Option[lila.tournament.Tournament])(implicit ctx: Context)
@import pov._

View File

@ -1,9 +1,7 @@
@(pov: Pov, bookmarkers: List[User] = Nil)(extra: Html)(implicit ctx: Context)
@(pov: Pov, bookmarkers: List[String] = Nil)(extra: Html)(implicit ctx: Context)
@import pov._
@bookmarkerLink(user: User) = {<a href="@routes.User.show(user.username)">@user.username</a>}
@defining("http://lichess.org" + routes.Round.watcher(gameId, color.name)) { url =>
<div class="undergame_box game_more">
<div class="more_top">
@ -18,7 +16,7 @@
<div class="bookmarkers inline_userlist">
<p>@trans.bookmarkedByNbPlayers(bookmarkers.size)</p>
<span class="list">
@Html(bookmarkers.map(bookmarkerLink).mkString(", "))
@Html(bookmarkers.map(userIdLinkMini).mkString(", "))
</span>
</div>
}

View File

@ -1,4 +1,4 @@
@(pov: Pov, version: Int, engine: Boolean, roomHtml: Option[Html], bookmarkers: List[User], analysed: Boolean, tour: Option[lila.tournament.Tournament])(implicit ctx: Context)
@(pov: Pov, version: Int, engine: Boolean, roomHtml: Option[Html], bookmarkers: List[String], analysed: Boolean, tour: Option[lila.tournament.Tournament])(implicit ctx: Context)
@import pov._

View File

@ -1,4 +1,4 @@
@(pov: Pov, version: Int, roomHtml: Html, bookmarkers: List[User], analysed: Boolean, tour: Option[lila.tournament.Tournament])(implicit ctx: Context)
@(pov: Pov, version: Int, roomHtml: Html, bookmarkers: List[String], analysed: Boolean, tour: Option[lila.tournament.Tournament])(implicit ctx: Context)
@import pov._

3
todo
View File

@ -33,9 +33,6 @@ make hand and finisher actors to avoid racing conditions
tournament monitor
all hub members should use userIds rather than usernames
tournament ties
tournament detect leavers and withdraw them (started) (also use force resign)
-> or show current tournament on every page, with (join) and (redraw) buttons
tournament warmup games
AI thinks during your time (premove?) http://en.lichess.org/forum/lichess-feedback/y-u-so-greedy-with-time-stockfish#4
- in fact it does not, but the UI clocks only update once the ai made the move
- solution: do AI asynchronously. Send player move events right away,