Skip to content

Commit

Permalink
Merge branch 'master' into tournament-reminder
Browse files Browse the repository at this point in the history
* master:
  remove websocket trap
  random improvements
  optimize player and watcher pages performances
  mongodb count -> size optimizations
  tweak move notifier
  • Loading branch information
ornicar committed Oct 26, 2012
2 parents fd85b54 + 6e6ee59 commit bd7ffe3
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 53 deletions.
9 changes: 4 additions & 5 deletions app/analyse/AnalysisRepo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,12 @@ final class AnalysisRepo(val collection: MongoCollection) {
def doneById(id: String): IO[Option[Analysis]] = byId(id) map { _ filter (_.done) }

def isDone(id: String): IO[Boolean] = io {
collection.count(DBObject("_id" -> id, "done" -> true)) > 0
collection.find(DBObject("_id" -> id, "done" -> true)).limit(1).size == 1
}

def userInProgress(uid: String): IO[Boolean] = io {
collection.count(
("fail" $exists false) ++
DBObject("uid" -> uid, "done" -> false)
) > 0
collection.find(
("fail" $exists false) ++ DBObject("uid" -> uid, "done" -> false)
).limit(1).size > 0
}
}
14 changes: 3 additions & 11 deletions app/controllers/Lobby.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,11 @@ object Lobby extends LilaController with Results {
private def featured = env.game.featured
private def openTours = env.tournament.repo.created

val home = Open { implicit ctx
Async {
renderHome(none, Ok)
}
}
val home = Open { implicit ctx Async { renderHome(none, Ok) } }

def handleNotFound(req: RequestHeader): Result =
handleNotFound(reqToCtx(req))
def handleNotFound(req: RequestHeader): Result = handleNotFound(reqToCtx(req))

def handleNotFound(implicit ctx: Context): Result =
Async {
renderHome(none, NotFound)
}
def handleNotFound(implicit ctx: Context): Result = Async { renderHome(none, NotFound) }

private def renderHome[A](myHook: Option[Hook], status: Status)(implicit ctx: Context): Promise[Result] =
preloader(
Expand Down
14 changes: 4 additions & 10 deletions app/controllers/Round.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ object Round extends LilaController with TheftPrevention with RoundEventPerforme
getInt("version"),
get("sri"),
get("tk"),
get("tr") | "-",
ctx).unsafePerformIO
}

Expand All @@ -56,18 +55,16 @@ object Round extends LilaController with TheftPrevention with RoundEventPerforme
pov.game.started.fold(
for {
roomHtml messenger render pov.game
bookmarkers bookmarkApi usersByGame pov.game
engine pov.opponent.userId.fold(
u userRepo isEngine u,
io(false))
bookmarkers pov.game.hasBookmarks.fold(bookmarkApi usersByGame pov.game, io(Nil))
engine pov.opponent.userId.fold(userRepo.isEngine, io(false))
analysed analyser has pov.gameId
tour tournamentRepo byId pov.game.tournamentId
} yield PreventTheft(pov) {
Ok(html.round.player(
pov,
version(pov.gameId),
engine,
roomHtml map { Html(_) },
roomHtml map Html.apply,
bookmarkers,
analysed,
tour = tour))
Expand All @@ -90,10 +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 pov.game.hasBookmarks.fold(bookmarkApi usersByGame pov.game, io(Nil))
roomHtml messenger renderWatcher pov.game
analysed analyser has pov.gameId
tour tournamentRepo byId pov.game.tournamentId
Expand Down
3 changes: 2 additions & 1 deletion app/forum/ForumEnv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ final class ForumEnv(
lazy val postApi = new PostApi(this, modLog, ForumPostMaxPerPage)

lazy val recent = new Recent(
env = this,
postRepo = postRepo,
postApi = postApi,
timeout = ForumRecentTimeout)

lazy val forms = new DataForm(captcha)
Expand Down
6 changes: 3 additions & 3 deletions app/forum/Recent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import security.{ Permission, Granter }

import scalaz.effects._

final class Recent(env: ForumEnv, timeout: Int) {
final class Recent(postRepo: PostRepo, postApi: PostApi, timeout: Int) {

val nb = 30

Expand All @@ -22,8 +22,8 @@ final class Recent(env: ForumEnv, timeout: Int) {
val invalidate: IO[Unit] = io(cache.invalidateAll)

private def fetch(staff: Boolean): IO[List[PostView]] = for {
posts env.postRepo.recent(nb)
views (posts map env.postApi.view).sequence
posts postRepo.recent(nb)
views (posts map postApi.view).sequence
} yield views collect {
case Some(v) if (staff || v.categ.slug != "staff") v
}
Expand Down
5 changes: 2 additions & 3 deletions app/http/Context.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ sealed abstract class Context(val req: RequestHeader, val me: Option[User]) {

def isAnon = !isAuth

def canSeeChat = me.fold(m !m.isChatBan, false)
def canSeeChat = me.fold(!_.isChatBan, false)

def isGranted(permission: Permission): Boolean =
me.fold(Granter(permission), false)
def isGranted(permission: Permission): Boolean = me.fold(Granter(permission), false)

def is(user: User): Boolean = me == Some(user)

Expand Down
8 changes: 2 additions & 6 deletions app/round/MoveNotifier.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@ import play.api.libs.concurrent._
import play.api.Play.current

final class MoveNotifier(
siteHubName: String,
lobbyHubName: String,
tournamentHubMasterName: String,
hubNames: List[String],
countMove: () Unit) {

lazy val hubRefs = List(siteHubName, lobbyHubName, tournamentHubMasterName) map { name
Akka.system.actorFor("/user/" + name)
}
lazy val hubRefs = hubNames map { name Akka.system.actorFor("/user/" + name) }

def apply(gameId: String, fen: String, lastMove: Option[String]) {
countMove()
Expand Down
4 changes: 1 addition & 3 deletions app/round/RoundEnv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ final class RoundEnv(
)), name = ActorRoundHubMaster)

private lazy val moveNotifier = new MoveNotifier(
siteHubName = ActorSiteHub,
lobbyHubName = ActorLobbyHub,
tournamentHubMasterName = ActorTournamentHubMaster,
hubNames = List(ActorSiteHub, ActorLobbyHub, ActorTournamentHubMaster),
countMove = countMove)

lazy val socket = new Socket(
Expand Down
2 changes: 0 additions & 2 deletions app/round/Socket.scala
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ final class Socket(
version: Option[Int],
uid: Option[String],
token: Option[String],
trap: String,
ctx: Context): IO[SocketPromise] = {
if (trap != "a") println("[websocket] trap %s %s".format(fullId, ctx.toString))
getPlayerPov(fullId) map { join(_, true, version, uid, token, ctx) }
}

Expand Down
7 changes: 2 additions & 5 deletions app/user/UserRepo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,8 @@ class UserRepo(collection: MongoCollection)
}

def isEngine(username: String): IO[Boolean] = io {
for {
obj collection.findOne(byIdQuery(username), DBObject("engine" -> true))
engine obj.getAs[Boolean]("engine")
} yield engine
} map (_ | false)
collection.find(byIdQuery(username) ++ DBObject("engine" -> true)).size != 0
}

def setBio(user: User, bio: String) = updateIO(user)($set("bio" -> bio))

Expand Down
2 changes: 1 addition & 1 deletion public/javascripts/big.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ $.widget("lichess.game", {
options: {
name: "game"
},
params: { tk: "--tkph--", tr: "a"},
params: { tk: "--tkph--" },
events: {
ack: function() {
clearTimeout(self.socketAckTimeout);
Expand Down
3 changes: 0 additions & 3 deletions todo
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
chat should autoscroll only when at bottom
finish flagged game
It's possible to join your own game and win it, which will then be displayed as a win and I saw players who abuse this to manipulate their stats.
player timeout depending on game duration
do not count games vs engine as win/loss
start chess960 after both player move https://fr.lichess.org/forum/lichess-feedback/clock-fairness-in-chess960-games
chess960 confirmation https://fr.lichess.org/forum/lichess-feedback/separate-960-lobby?page=1#7
use POST instead of GET where it makes sense
Expand Down

0 comments on commit bd7ffe3

Please sign in to comment.