Revert "attempt to fix memory leak by making simul cache synchronous"

This reverts commit 9538e3b6c5.

Conflicts:
	modules/game/src/main/Cached.scala
This commit is contained in:
Thibault Duplessis 2014-12-30 11:37:42 +01:00
parent 9c8a2dc5c3
commit bec08d73de
5 changed files with 53 additions and 48 deletions

View file

@ -95,16 +95,17 @@ object User extends LilaController {
private def userGames(u: UserModel, filterOption: Option[String], page: Int)(implicit ctx: Context) = {
import lila.app.mashup.GameFilter.{ All, Playing }
val filterName = filterOption | {
Env.game.cached.isPlayingSimul(u.id).fold(Playing, All).name
filterOption.fold({
Env.game.cached isPlayingSimul u.id map (_.fold(Playing, All).name)
})(fuccess) flatMap { filterName =>
GameFilterMenu.paginatorOf(
user = u,
info = none,
filter = GameFilterMenu.currentOf(GameFilterMenu.all, filterName),
me = ctx.me,
page = page
) map { html.user.games(u, _, filterName) }
}
GameFilterMenu.paginatorOf(
user = u,
info = none,
filter = GameFilterMenu.currentOf(GameFilterMenu.all, filterName),
me = ctx.me,
page = page
) map { html.user.games(u, _, filterName) }
}
def list = Open { implicit ctx =>

View file

@ -59,23 +59,25 @@ object UserInfo {
(ctx.me ?? Granter(_.UserSpy) ?? { relationApi.nbBlockers(user.id) map (_.some) }) zip
postApi.nbByUser(user.id) zip
isDonor(user.id) zip
PlayTime(user) map {
PlayTime(user) flatMap {
case (((((((((((nbUsers, ranks), nbPlaying), nbImported), crosstable), ratingChart), nbFollowing), nbFollowers), nbBlockers), nbPosts), isDonor), playTime) =>
new UserInfo(
user = user,
ranks = ranks,
nbUsers = nbUsers,
nbPlaying = nbPlaying,
hasSimul = (nbPlaying > 0 && gameCached.isPlayingSimul(user.id)),
crosstable = crosstable,
nbBookmark = bookmarkApi countByUser user,
nbImported = nbImported,
ratingChart = ratingChart,
nbFollowing = nbFollowing,
nbFollowers = nbFollowers,
nbBlockers = nbBlockers,
nbPosts = nbPosts,
playTime = playTime,
donor = isDonor)
(nbPlaying > 0) ?? gameCached.isPlayingSimul(user.id) map { hasSimul =>
new UserInfo(
user = user,
ranks = ranks,
nbUsers = nbUsers,
nbPlaying = nbPlaying,
hasSimul = hasSimul,
crosstable = crosstable,
nbBookmark = bookmarkApi countByUser user,
nbImported = nbImported,
ratingChart = ratingChart,
nbFollowing = nbFollowing,
nbFollowers = nbFollowers,
nbBlockers = nbBlockers,
nbPosts = nbPosts,
playTime = playTime,
donor = isDonor)
}
}
}

View file

@ -7,7 +7,7 @@ import play.api.libs.json.JsObject
import lila.db.api.$count
import lila.db.BSON._
import lila.memo.{ AsyncCache, MixedCache, MongoCache, ExpireSetMemo, Builder }
import lila.memo.{ AsyncCache, MongoCache, ExpireSetMemo, Builder }
import lila.user.{ User, UidNb }
import tube.gameTube
import UidNb.UidNbBSONHandler
@ -25,13 +25,11 @@ final class Cached(
private implicit val userHandler = User.userBSONHandler
private val isPlayingSimulCache = MixedCache[String, Boolean](
private val isPlayingSimulCache = AsyncCache[String, Boolean](
f = userId => GameRepo.countPlayingRealTime(userId) map (1 <),
awaitTime = 10.milliseconds,
timeToLive = 15.seconds,
default = _ => false)
timeToLive = 10.seconds)
val isPlayingSimul: String => Boolean = isPlayingSimulCache.get
val isPlayingSimul: String => Fu[Boolean] = isPlayingSimulCache.apply _
val rematch960 = new ExpireSetMemo(3.hours)

View file

@ -28,7 +28,7 @@ final class Env(
prefApi: lila.pref.PrefApi,
chatApi: lila.chat.ChatApi,
historyApi: lila.history.HistoryApi,
isPlayingSimul: String => Boolean,
isPlayingSimul: String => Fu[Boolean],
scheduler: lila.common.Scheduler) {
private val settings = new {
@ -71,8 +71,6 @@ final class Env(
}: Receive) orElse actorMapReceive
}), name = ActorMapName)
scheduler.message(2.1 seconds)(roundMap -> actorApi.GetNbRounds)
private var nbRounds = 0
def count() = nbRounds
@ -163,6 +161,8 @@ final class Env(
lazy val noteApi = new NoteApi(db(CollectionNote))
scheduler.message(2.1 seconds)(roundMap -> actorApi.GetNbRounds)
system.actorOf(
Props(classOf[Titivate], roundMap, hub.actor.bookmark),
name = "titivate")

View file

@ -27,7 +27,7 @@ private[round] final class Socket(
socketTimeout: Duration,
disconnectTimeout: Duration,
ragequitTimeout: Duration,
isPlayingSimul: String => Boolean) extends SocketActor[Member](uidTimeout) {
isPlayingSimul: String => Fu[Boolean]) extends SocketActor[Member](uidTimeout) {
private var hasAi = false
@ -43,7 +43,7 @@ private[round] final class Socket(
var userId = none[String]
def ping {
if (isGone) notifyGone(color, false)
isGone foreach { _ ?? notifyGone(color, false) }
if (bye > 0) bye = bye - 1
time = nowMillis
}
@ -52,9 +52,10 @@ private[round] final class Socket(
}
private def isBye = bye > 0
def isGone = {
time < (nowMillis - isBye.fold(ragequitTimeout, disconnectTimeout).toMillis)
} && !userId.??(isPlayingSimul)
def isGone =
if (time < (nowMillis - isBye.fold(ragequitTimeout, disconnectTimeout).toMillis))
(userId ?? isPlayingSimul) map (!_)
else fuccess(false)
}
private val whitePlayer = new Player(White)
@ -102,19 +103,22 @@ private[round] final class Socket(
broom
if (timeBomb.boom) self ! PoisonPill
else if (!hasAi) Color.all foreach { c =>
if (playerGet(c, _.isGone)) notifyGone(c, true)
playerGet(c, _.isGone) foreach { _ ?? notifyGone(c, true) }
}
case GetVersion => sender ! history.getVersion
case IsGone(color) => sender ! playerGet(color, _.isGone)
case IsGone(color) => playerGet(color, _.isGone) pipeTo sender
case GetSocketStatus => sender ! SocketStatus(
version = history.getVersion,
whiteOnGame = ownerOf(White).isDefined,
whiteIsGone = playerGet(White, _.isGone),
blackOnGame = ownerOf(Black).isDefined,
blackIsGone = playerGet(Black, _.isGone))
case GetSocketStatus =>
playerGet(White, _.isGone) zip playerGet(Black, _.isGone) map {
case (whiteIsGone, blackIsGone) => SocketStatus(
version = history.getVersion,
whiteOnGame = ownerOf(White).isDefined,
whiteIsGone = whiteIsGone,
blackOnGame = ownerOf(Black).isDefined,
blackIsGone = blackIsGone)
} pipeTo sender
case Join(uid, user, version, color, playerId, ip, userTv) =>
val (enumerator, channel) = Concurrent.broadcast[JsValue]