mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[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
This commit is contained in:
@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user