From 0ab871e09fc64c374f9bb9f0c32dd5e6c6937fde Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Wed, 28 Apr 2021 10:05:54 +0200 Subject: [PATCH] renew puzzle sessions during provisional rating period --- modules/puzzle/src/main/PuzzleSession.scala | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/puzzle/src/main/PuzzleSession.scala b/modules/puzzle/src/main/PuzzleSession.scala index 68fcce90b2..c9fdeaf6bc 100644 --- a/modules/puzzle/src/main/PuzzleSession.scala +++ b/modules/puzzle/src/main/PuzzleSession.scala @@ -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,