From f8bf12ddc4614f5dfaa5dca908351642e4424e05 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Thu, 26 Sep 2013 11:05:30 +0200 Subject: [PATCH] redefine abandoned games --- modules/game/src/main/Game.scala | 6 ++---- modules/game/src/main/Query.scala | 8 +++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/game/src/main/Game.scala b/modules/game/src/main/Game.scala index 3c3dd29d21..adaab1b423 100644 --- a/modules/game/src/main/Game.scala +++ b/modules/game/src/main/Game.scala @@ -313,9 +313,7 @@ case class Game( def olderThan(seconds: Int) = updatedAt.??(_ < DateTime.now - seconds.seconds) - def abandoned = updatedAt ?? { u ⇒ - (status <= Status.Started) && (u <= Game.abandonedDate) - } + def abandoned = (status <= Status.Started) && (updatedAt | createdAt) < Game.abandonedDate def hasBookmarks = bookmarks > 0 @@ -384,7 +382,7 @@ object Game { val updatedAt = "ua" } - def abandonedDate = DateTime.now - 10.days + def abandonedDate = DateTime.now - 7.days def takeGameId(fullId: String) = fullId take gameIdSize def takePlayerId(fullId: String) = fullId drop gameIdSize diff --git a/modules/game/src/main/Query.scala b/modules/game/src/main/Query.scala index fdcee7532a..fe93789bc4 100644 --- a/modules/game/src/main/Query.scala +++ b/modules/game/src/main/Query.scala @@ -66,7 +66,13 @@ object Query { def finishByClock = playable ++ clock(true) ++ Json.obj( createdAt -> $gt($date(DateTime.now - 3.hour))) - def abandoned = notFinished ++ Json.obj(updatedAt -> $lt($date(Game.abandonedDate))) + def abandoned = { + val date = $date(Game.abandonedDate) + notFinished ++ $or(Seq( + Json.obj(updatedAt -> $lt(date)), + Json.obj(updatedAt -> $exists(false), createdAt -> $lt(date)) + )) + } val sortCreated = $sort desc createdAt