@@ -57,21 +57,31 @@ final class EvalCacheApi(mongo: Mongo)(using
5757 multi.register(sri, e.copy(fens = e.fens))
5858
5959 def put (sri : Sri , user : User .Id , e : EvalPut ): Unit =
60- truster
61- .get(user)
62- .foreach:
63- _.filter(_.isEnough).foreach: trust =>
64- makeInput(
65- e.variant,
66- e.fen,
67- Eval (
68- pvs = e.pvs,
69- knodes = e.knodes,
70- depth = e.depth,
71- by = user,
72- trust = trust
73- )
74- ).foreach(putTrusted(sri, user, _))
60+ if isStorableDepth(e.depth)
61+ then
62+ truster
63+ .get(user)
64+ .foreach:
65+ _.filter(_.isEnough).foreach: trust =>
66+ makeInput(
67+ e.variant,
68+ e.fen,
69+ Eval (
70+ pvs = e.pvs,
71+ knodes = e.knodes,
72+ depth = e.depth,
73+ by = user,
74+ trust = trust
75+ )
76+ ).foreach(putTrusted(sri, user, _))
77+
78+ // reduce the number of evals stored and,
79+ // perhaps more importantly, distributed to subscribers
80+ private def isStorableDepth (depth : Depth ) =
81+ if depth < 20 then false
82+ else if depth < 30 then true
83+ else if depth < 50 then depth.value % 2 == 0
84+ else depth.value % 5 == 0
7585
7686 private def monitorRequest [A ](fen : Fen .Full , mon : Monitor .evalCache.Style )(res : Option [A ]): Option [A ] =
7787 Fen
@@ -96,7 +106,7 @@ final class EvalCacheApi(mongo: Mongo)(using
96106
97107 private def putTrusted (sri : Sri , user : User .Id , input : Input ): Future [Unit ] =
98108 mongo.evalCacheColl.flatMap: c =>
99- EvalCacheValidator (input) match
109+ validate (input) match
100110 case Left (error) =>
101111 Logger (" EvalCacheApi.put" ).info(s " Invalid from ${user} $error ${input.fen}" )
102112 Future .successful(())
@@ -128,9 +138,7 @@ final class EvalCacheApi(mongo: Mongo)(using
128138 upgrade.onEval(input, sri)
129139 multi.onEval(input, sri)
130140
131- private object EvalCacheValidator :
132-
133- def apply (in : EvalCacheEntry .Input ): Either [ErrorStr , Unit ] =
141+ private def validate (in : EvalCacheEntry .Input ): Either [ErrorStr , Unit ] =
134142 in.eval.pvs.traverse_ { pv =>
135143 chess.Replay .boardsFromUci(pv.moves.value.toList, in.fen.some, in.situation.variant)
136144 }
0 commit comments