puzzle curators can discard the daily puzzle by downvoting it

pull/8432/head
Thibault Duplessis 2021-03-20 09:21:23 +01:00
parent a0abcd122c
commit 838f7f9788
3 changed files with 10 additions and 5 deletions

View File

@ -19,7 +19,7 @@ final private[puzzle] class DailyPuzzle(
private val cache = private val cache =
cacheApi.unit[Option[DailyPuzzle.WithHtml]] { cacheApi.unit[Option[DailyPuzzle.WithHtml]] {
_.refreshAfterWrite(5 minutes) _.refreshAfterWrite(1 minutes)
.buildAsyncFuture(_ => find) .buildAsyncFuture(_ => find)
} }
@ -43,7 +43,7 @@ final private[puzzle] class DailyPuzzle(
private def findCurrent = private def findCurrent =
colls.puzzle { colls.puzzle {
_.find($doc(F.day $gt DateTime.now.minusMinutes(24 * 60 - 15))) _.find($doc(F.day $gt DateTime.now.minusDays(1)))
.one[Puzzle] .one[Puzzle]
} }

View File

@ -97,7 +97,7 @@ final class PuzzleApi(
import Puzzle.{ BSONFields => F } import Puzzle.{ BSONFields => F }
coll.one[Bdoc]( coll.one[Bdoc](
$id(puzzleId.value), $id(puzzleId.value),
$doc(F.voteUp -> true, F.voteDown -> true, F.id -> false) $doc(F.voteUp -> true, F.voteDown -> true, F.day -> true, F.id -> false)
) flatMap { ) flatMap {
_ ?? { doc => _ ?? { doc =>
val prevUp = ~doc.int(F.voteUp) val prevUp = ~doc.int(F.voteUp)
@ -111,7 +111,12 @@ final class PuzzleApi(
F.voteUp -> up, F.voteUp -> up,
F.voteDown -> down, F.voteDown -> down,
F.vote -> ((up - down).toFloat / (up + down)) F.vote -> ((up - down).toFloat / (up + down))
) ) ++ {
(newVote <= -100 && doc
.getAsOpt[DateTime](F.day)
.exists(_ isAfter DateTime.now.minusDays(1))) ??
$unset(F.day)
}
) )
.void .void
} }

View File

@ -59,7 +59,7 @@ final private class PuzzleTrustApi(colls: PuzzleColls)(implicit ec: scala.concur
(rating - 1500) / 300 (rating - 1500) / 300
} atLeast 0 } atLeast 0
private def patronBonus(user: User) = (~user.planMonths * 5) atMost 20 private def patronBonus(user: User) = (~user.planMonths * 5) atMost 15
private def modBonus(user: User) = private def modBonus(user: User) =
if (user.roles.exists(_ contains "ROLE_PUZZLE_CURATOR")) 100 if (user.roles.exists(_ contains "ROLE_PUZZLE_CURATOR")) 100