load less users from db

This commit is contained in:
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 = def countByUser(user: User): Int =
cached.count(user.id) cached.count(user.id)
def usersByGame(game: DbGame): IO[List[User]] = def userIdsByGame(game: DbGame): IO[List[String]] =
if (game.hasBookmarks) for { if (game.hasBookmarks) bookmarkRepo userIdsByGameId game.id
userIds bookmarkRepo userIdsByGameId game.id
users (userIds map userRepo.byId).sequence
} yield users.flatten
else io(Nil) else io(Nil)
def removeByGame(game: DbGame): IO[Unit] = def removeByGame(game: DbGame): IO[Unit] =

View file

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

View file

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

View file

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

View file

@ -41,6 +41,13 @@ trait UserHelper {
userId: String, userId: String,
cssClass: Option[String]): Html = userIdLink(userId.some, cssClass) 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( def userLink(
user: User, user: User,
cssClass: Option[String] = None, 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._ @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._ @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 => @defining("http://lichess.org" + routes.Round.watcher(gameId, color.name)) { url =>
<div class="undergame_box game_more"> <div class="undergame_box game_more">
<div class="more_top"> <div class="more_top">
@ -18,7 +16,7 @@
<div class="bookmarkers inline_userlist"> <div class="bookmarkers inline_userlist">
<p>@trans.bookmarkedByNbPlayers(bookmarkers.size)</p> <p>@trans.bookmarkedByNbPlayers(bookmarkers.size)</p>
<span class="list"> <span class="list">
@Html(bookmarkers.map(bookmarkerLink).mkString(", ")) @Html(bookmarkers.map(userIdLinkMini).mkString(", "))
</span> </span>
</div> </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._ @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._ @import pov._

3
todo
View file

@ -33,9 +33,6 @@ make hand and finisher actors to avoid racing conditions
tournament monitor tournament monitor
all hub members should use userIds rather than usernames all hub members should use userIds rather than usernames
tournament ties 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 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 - 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, - solution: do AI asynchronously. Send player move events right away,