renew puzzle sessions during provisional rating period

pull/8795/head
Thibault Duplessis 2021-04-28 10:05:54 +02:00
parent 44ce134c6b
commit 0ab871e09f
1 changed files with 8 additions and 1 deletions

View File

@ -21,6 +21,8 @@ private case class PuzzleSession(
)
def next = copy(positionInPath = positionInPath + 1)
def brandNew = positionInPath == 0
override def toString = s"$path:$positionInPath"
}
@ -175,10 +177,15 @@ final class PuzzleSessionApi(
theme: PuzzleTheme.Key
): Fu[PuzzleSession] =
sessions.getFuture(user.id, _ => createSessionFor(user, theme)) flatMap { current =>
if (current.path.theme == theme) fuccess(current)
if (current.path.theme == theme && !shouldChangeSession(user, current)) fuccess(current)
else createSessionFor(user, theme, current.difficulty) tap { sessions.put(user.id, _) }
}
private def shouldChangeSession(user: User, session: PuzzleSession) = !session.brandNew && {
val perf = user.perfs.puzzle
perf.clueless || (perf.provisional && perf.nb % 5 == 0)
}
private def createSessionFor(
user: User,
theme: PuzzleTheme.Key,