better rate limit for seek creation
This commit is contained in:
parent
844a03dc7b
commit
f5bc0c0ff7
|
@ -7,7 +7,7 @@ import views._
|
|||
|
||||
object ForumPost extends LilaController with ForumController {
|
||||
|
||||
private val CreateRateLimit = new lila.memo.RateLimitNumberByKey(4, 5 minutes)
|
||||
private val CreateRateLimit = new lila.memo.RateLimitByKey(4, 5 minutes)
|
||||
|
||||
def search(text: String, page: Int) = OpenBody { implicit ctx =>
|
||||
NotForKids {
|
||||
|
|
|
@ -8,7 +8,7 @@ import views._
|
|||
|
||||
object ForumTopic extends LilaController with ForumController {
|
||||
|
||||
private val CreateRateLimit = new lila.memo.RateLimitNumberByKey(2, 5 minutes)
|
||||
private val CreateRateLimit = new lila.memo.RateLimitByKey(2, 5 minutes)
|
||||
|
||||
def form(categSlug: String) = Open { implicit ctx =>
|
||||
NotForKids {
|
||||
|
|
|
@ -19,8 +19,7 @@ object Setup extends LilaController with TheftPrevention {
|
|||
|
||||
private def env = Env.setup
|
||||
|
||||
private val FormRateLimit = new lila.memo.RateLimitByKey(500 millis)
|
||||
private val PostRateLimit = new lila.memo.RateLimitByKey(500 millis)
|
||||
private val PostRateLimit = new lila.memo.RateLimitByKey(5, 1 minute)
|
||||
|
||||
def aiForm = Open { implicit ctx =>
|
||||
if (HTTPRequest isXhr ctx.req) {
|
||||
|
@ -92,10 +91,8 @@ object Setup extends LilaController with TheftPrevention {
|
|||
}
|
||||
|
||||
def hookForm = Open { implicit ctx =>
|
||||
if (HTTPRequest isXhr ctx.req) FormRateLimit(ctx.req.remoteAddress) {
|
||||
NoPlaybanOrCurrent {
|
||||
env.forms.hookFilled(timeModeString = get("time")) map { html.setup.hook(_) }
|
||||
}
|
||||
if (HTTPRequest isXhr ctx.req) NoPlaybanOrCurrent {
|
||||
env.forms.hookFilled(timeModeString = get("time")) map { html.setup.hook(_) }
|
||||
}
|
||||
else fuccess {
|
||||
Redirect(routes.Lobby.home + "#hook")
|
||||
|
|
|
@ -21,26 +21,10 @@ final class RateLimitGlobal(duration: Duration) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* very simple side effect throttler
|
||||
* that allows one call per duration and per key,
|
||||
*/
|
||||
final class RateLimitByKey(duration: Duration) {
|
||||
|
||||
private val storage = new ExpireSetMemo(ttl = duration)
|
||||
|
||||
def apply[A: Zero](key: String)(op: => A): A = {
|
||||
(!storage.get(key)) ?? {
|
||||
storage put key
|
||||
op
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* side effect throttler that allows X ops per Y unit of time
|
||||
*/
|
||||
final class RateLimitNumberByKey(nb: Int, duration: Duration) {
|
||||
final class RateLimitByKey(nb: Int, duration: Duration) {
|
||||
|
||||
private val storage = Builder.expiry[String, Int](ttl = duration)
|
||||
|
||||
|
|
Loading…
Reference in a new issue