fix bookmarked games paginator

This commit is contained in:
Thibault Duplessis 2013-05-15 13:54:10 -03:00
parent 010b25f9dd
commit 1d53d41155
3 changed files with 5 additions and 21 deletions

View file

@ -11,10 +11,7 @@ import play.modules.reactivemongo.json.ImplicitBSONHandlers._
import org.joda.time.DateTime
import scala.concurrent.Future
case class Bookmark(
game: lila.game.Game,
user: lila.user.User,
date: org.joda.time.DateTime)
case class Bookmark(game: lila.game.Game, user: lila.user.User)
// db.bookmark.ensureIndex({g:1})
// db.bookmark.ensureIndex({u:1})

View file

@ -13,7 +13,7 @@ import play.api.libs.json._
import play.modules.reactivemongo.json.ImplicitBSONHandlers._
import org.joda.time.DateTime
final class PaginatorBuilder(maxPerPage: Int) {
private[bookmark] final class PaginatorBuilder(maxPerPage: Int) {
def byUser(user: User, page: Int): Fu[Paginator[Bookmark]] =
paginator(new UserAdapter(user), page)
@ -30,23 +30,11 @@ final class PaginatorBuilder(maxPerPage: Int) {
def nbResults: Fu[Int] = $count(selector)
def slice(offset: Int, length: Int): Fu[Seq[Bookmark]] = for {
pairs $query(selector)
.sort(sorting)
.skip(offset)
.cursor[JsObject] toList length map2 { (obj: JsObject)
obj str "g" flatMap { gameId
obj.get[DateTime]("d") map { (gameId, _) }
}
} map (_.flatten)
gameIds $primitive(selector, "g", _ sort sorting skip offset)(_.asOpt[String])
games lila.game.tube.gameTube |> { implicit t
$find.byIds[Game](pairs map (_._1))
$find.byOrderedIds[Game](gameIds)
}
bookmarks = pairs map { pair
games find (_.id == pair._1) map { game
Bookmark(game, user, pair._2)
}
}
} yield bookmarks.toList.flatten
} yield games map { g Bookmark(g, user) }
private def selector = BookmarkRepo userIdQuery user.id
private def sorting = $sort desc "d"

1
todo
View file

@ -22,7 +22,6 @@ tournament berserker = half time, double points
chat icons (k) (K)
blind accessible
make hand and finisher actors to avoid racing conditions
all hub members should use userIds rather than usernames
tournament ties
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