diff options
author | 2023-12-16 11:53:42 +0000 | |
---|---|---|
committer | 2023-12-16 12:53:42 +0100 | |
commit | d56a8d095e8fe84422ef4098d1e1a25198da17a1 (patch) | |
tree | cb34cb50335098492c863e4630dfd0b8da10d6c5 /internal/middleware/ratelimit.go | |
parent | [docs]: Update FAQ and ROADMAP (#2458) (diff) | |
download | gotosocial-d56a8d095e8fe84422ef4098d1e1a25198da17a1.tar.xz |
[performance] simpler throttling logic (#2407)
* reduce complexity of throttling logic to use 1 queue and an atomic int
* use atomic add instead of CAS, add throttling test
Diffstat (limited to 'internal/middleware/ratelimit.go')
-rw-r--r-- | internal/middleware/ratelimit.go | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/internal/middleware/ratelimit.go b/internal/middleware/ratelimit.go index a59a3e608..57055fe70 100644 --- a/internal/middleware/ratelimit.go +++ b/internal/middleware/ratelimit.go @@ -29,6 +29,8 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/util" "github.com/ulule/limiter/v3" "github.com/ulule/limiter/v3/drivers/store/memory" + + apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util" ) const rateLimitPeriod = 5 * time.Minute @@ -141,10 +143,12 @@ func RateLimit(limit int, exceptions []string) gin.HandlerFunc { if context.Reached { // Return JSON error message for // consistency with other endpoints. - c.AbortWithStatusJSON( + apiutil.Data(c, http.StatusTooManyRequests, - gin.H{"error": "rate limit reached"}, + apiutil.AppJSON, + apiutil.ErrorRateLimitReached, ) + c.Abort() return } |