fix user lists

This commit is contained in:
Thibault Duplessis 2014-08-06 10:56:21 +02:00
parent 842871db87
commit eb155c5abb
7 changed files with 20 additions and 13 deletions

View file

@ -44,7 +44,7 @@ object User extends LilaController {
def online = Open { implicit req =>
val max = 1000
UserRepo.byIdsSortRating(env.onlineUserIdMemo.keys take max) map { html.user.online(_, max) }
UserRepo.byIdsSortRating(env.onlineUserIdMemo.keys, max) map { html.user.online(_, max) }
}
private def filter(

View file

@ -32,7 +32,7 @@ object TeamInfo {
mine = me.??(m => api.belongsTo(team.id, m.id))
requestedByMe !mine ?? me.??(m => RequestRepo.exists(team.id, m.id))
userIds MemberRepo userIdsByTeam team.id
bestPlayers UserRepo.byIdsSortRating(userIds take 10)
bestPlayers UserRepo.byIdsSortRating(userIds, 10)
averageRating UserRepo.idsAverageRating(userIds)
toints UserRepo.idsSumToints(userIds)
forumNbPosts getForumNbPosts(team.id)

View file

@ -171,8 +171,10 @@ trait UserHelper { self: I18nHelper with StringHelper =>
val progress = if (withProgress) s" ${showProgress(user.progress)}" else ""
val space = if (withOnline) " " else ""
val dataIcon = if (withOnline) """ data-icon="r"""" else ""
val rating = (user.perfs.bestPerf ifTrue withBestRating) ?? {
case (pt, perf) => s" ${showPerfRating(pt, perf, "hint--bottom")}"
val rating = withBestRating ?? {
user.perfs.bestPerf ?? {
case (pt, perf) => s" ${showPerfRating(pt, perf, "hint--bottom")}"
}
}
s"""<a$dataIcon $klass $href>$space$titleS$content$rating$progress</a>"""
}

View file

@ -42,11 +42,16 @@
<div class="user_lists">
<div class="user_top">
<h2>@trans.onlinePlayers()</h2>
<ul>
@online.map { u =>
<li>@userLink(u, withBestRating = true, cssClass="revert-underline".some)</li>
}
</ul>
<table><tbody>
@online.map { u =>
<tr>
<td>@userLink(u, cssClass="revert-underline".some)</td>
<td>@u.perfs.bestPerf.map {
case (pt, p) => {@showPerfRating(pt, p, "hint--bottom")}
}</td>
</tr>
}
</tbody></table>
</div>
<a class="more" href="@routes.User.online">@trans.more() »</a>
</div>

View file

@ -48,7 +48,7 @@ final class Cached(
timeToLive = 20 minutes)
val topOnline = AsyncCache(
(nb: Int) => UserRepo.byIdsSortRating(onlineUserIdMemo.keys take nb),
(nb: Int) => UserRepo.byIdsSortRating(onlineUserIdMemo.keys, nb),
timeToLive = 2 seconds)
val topToints = AsyncCache(

View file

@ -31,7 +31,7 @@ case class Perfs(
def bestPerf: Option[(PerfType, Perf)] = {
val ps = PerfType.nonPoolPuzzle map { pt => pt -> apply(pt) }
val minNb = ps.foldLeft(0)(_ + _._2.nb) / 10
val minNb = math.max(1, ps.foldLeft(0)(_ + _._2.nb) / 10)
ps.foldLeft(none[(PerfType, Perf)]) {
case (ro, p) if p._2.nb >= minNb => ro.fold(p.some) { r =>
Some(if (p._2.intRating > r._2.intRating) p else r)

View file

@ -65,8 +65,8 @@ trait UserRepo {
def nameds(usernames: List[String]): Fu[List[User]] = $find byIds usernames.map(normalize)
def byIdsSortRating(ids: Iterable[ID]) =
$find($query byIds ids sort sortPerfDesc(PerfType.Standard.key))
def byIdsSortRating(ids: Iterable[ID], nb: Int) =
$find($query byIds ids sort sortPerfDesc(PerfType.Standard.key), nb)
def allSortToints(nb: Int) = $find($query.all sort ($sort desc F.toints), nb)