mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-30 03:12:24 -05: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:
parent
1312695c46
commit
d56a8d095e
4 changed files with 208 additions and 40 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue