@@ -57,21 +57,31 @@ final class EvalCacheApi(mongo: Mongo)(using
57
57
multi.register(sri, e.copy(fens = e.fens))
58
58
59
59
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
75
85
76
86
private def monitorRequest [A ](fen : Fen .Full , mon : Monitor .evalCache.Style )(res : Option [A ]): Option [A ] =
77
87
Fen
@@ -96,7 +106,7 @@ final class EvalCacheApi(mongo: Mongo)(using
96
106
97
107
private def putTrusted (sri : Sri , user : User .Id , input : Input ): Future [Unit ] =
98
108
mongo.evalCacheColl.flatMap: c =>
99
- EvalCacheValidator (input) match
109
+ validate (input) match
100
110
case Left (error) =>
101
111
Logger (" EvalCacheApi.put" ).info(s " Invalid from ${user} $error ${input.fen}" )
102
112
Future .successful(())
@@ -128,9 +138,7 @@ final class EvalCacheApi(mongo: Mongo)(using
128
138
upgrade.onEval(input, sri)
129
139
multi.onEval(input, sri)
130
140
131
- private object EvalCacheValidator :
132
-
133
- def apply (in : EvalCacheEntry .Input ): Either [ErrorStr , Unit ] =
141
+ private def validate (in : EvalCacheEntry .Input ): Either [ErrorStr , Unit ] =
134
142
in.eval.pvs.traverse_ { pv =>
135
143
chess.Replay .boardsFromUci(pv.moves.value.toList, in.fen.some, in.situation.variant)
136
144
}
0 commit comments