Skip to content

Commit

Permalink
load less users from db
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Oct 28, 2012
1 parent 7d03608 commit d88a9f5
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 19 deletions.
7 changes: 2 additions & 5 deletions app/bookmark/BookmarkApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/Analyse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/Round.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/user/Cached.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions app/user/UserHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/views/analyse/replay.scala.html
Original file line number Diff line number Diff line change
@@ -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._

Expand Down
6 changes: 2 additions & 4 deletions app/views/game/more.scala.html
Original file line number Diff line number Diff line change
@@ -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:https://lichess.org" + routes.Round.watcher(gameId, color.name)) { url =>
<div class="undergame_box game_more">
<div class="more_top">
Expand All @@ -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>
}
Expand Down
2 changes: 1 addition & 1 deletion app/views/round/player.scala.html
Original file line number Diff line number Diff line change
@@ -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._

Expand Down
2 changes: 1 addition & 1 deletion app/views/round/watcher.scala.html
Original file line number Diff line number Diff line change
@@ -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._

Expand Down
3 changes: 0 additions & 3 deletions todo
Original file line number Diff line number Diff line change
Expand Up @@ -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:https://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,
Expand Down

0 comments on commit d88a9f5

Please sign in to comment.