mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-17 01:57:34 -06:00
[chore]: Bump github.com/ulule/limiter/v3 from 3.11.1 to 3.11.2 (#1841)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
parent
2e7043be95
commit
e50b228539
6 changed files with 21 additions and 87 deletions
35
vendor/github.com/ulule/limiter/v3/drivers/store/memory/store.go
generated
vendored
35
vendor/github.com/ulule/limiter/v3/drivers/store/memory/store.go
generated
vendored
|
|
@ -2,11 +2,11 @@ package memory
|
|||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ulule/limiter/v3"
|
||||
"github.com/ulule/limiter/v3/drivers/store/common"
|
||||
"github.com/ulule/limiter/v3/internal/bytebuffer"
|
||||
)
|
||||
|
||||
// Store is the in-memory store.
|
||||
|
|
@ -35,11 +35,7 @@ func NewStoreWithOptions(options limiter.StoreOptions) limiter.Store {
|
|||
|
||||
// Get returns the limit for given identifier.
|
||||
func (store *Store) Get(ctx context.Context, key string, rate limiter.Rate) (limiter.Context, error) {
|
||||
buffer := bytebuffer.New()
|
||||
defer buffer.Close()
|
||||
buffer.Concat(store.Prefix, ":", key)
|
||||
|
||||
count, expiration := store.cache.Increment(buffer.String(), 1, rate.Period)
|
||||
count, expiration := store.cache.Increment(store.getCacheKey(key), 1, rate.Period)
|
||||
|
||||
lctx := common.GetContextFromState(time.Now(), rate, expiration, count)
|
||||
return lctx, nil
|
||||
|
|
@ -47,11 +43,7 @@ func (store *Store) Get(ctx context.Context, key string, rate limiter.Rate) (lim
|
|||
|
||||
// Increment increments the limit by given count & returns the new limit value for given identifier.
|
||||
func (store *Store) Increment(ctx context.Context, key string, count int64, rate limiter.Rate) (limiter.Context, error) {
|
||||
buffer := bytebuffer.New()
|
||||
defer buffer.Close()
|
||||
buffer.Concat(store.Prefix, ":", key)
|
||||
|
||||
newCount, expiration := store.cache.Increment(buffer.String(), count, rate.Period)
|
||||
newCount, expiration := store.cache.Increment(store.getCacheKey(key), count, rate.Period)
|
||||
|
||||
lctx := common.GetContextFromState(time.Now(), rate, expiration, newCount)
|
||||
return lctx, nil
|
||||
|
|
@ -59,11 +51,7 @@ func (store *Store) Increment(ctx context.Context, key string, count int64, rate
|
|||
|
||||
// Peek returns the limit for given identifier, without modification on current values.
|
||||
func (store *Store) Peek(ctx context.Context, key string, rate limiter.Rate) (limiter.Context, error) {
|
||||
buffer := bytebuffer.New()
|
||||
defer buffer.Close()
|
||||
buffer.Concat(store.Prefix, ":", key)
|
||||
|
||||
count, expiration := store.cache.Get(buffer.String(), rate.Period)
|
||||
count, expiration := store.cache.Get(store.getCacheKey(key), rate.Period)
|
||||
|
||||
lctx := common.GetContextFromState(time.Now(), rate, expiration, count)
|
||||
return lctx, nil
|
||||
|
|
@ -71,12 +59,17 @@ func (store *Store) Peek(ctx context.Context, key string, rate limiter.Rate) (li
|
|||
|
||||
// Reset returns the limit for given identifier.
|
||||
func (store *Store) Reset(ctx context.Context, key string, rate limiter.Rate) (limiter.Context, error) {
|
||||
buffer := bytebuffer.New()
|
||||
defer buffer.Close()
|
||||
buffer.Concat(store.Prefix, ":", key)
|
||||
|
||||
count, expiration := store.cache.Reset(buffer.String(), rate.Period)
|
||||
count, expiration := store.cache.Reset(store.getCacheKey(key), rate.Period)
|
||||
|
||||
lctx := common.GetContextFromState(time.Now(), rate, expiration, count)
|
||||
return lctx, nil
|
||||
}
|
||||
|
||||
// getCacheKey returns the full path for an identifier.
|
||||
func (store *Store) getCacheKey(key string) string {
|
||||
buffer := strings.Builder{}
|
||||
buffer.WriteString(store.Prefix)
|
||||
buffer.WriteString(":")
|
||||
buffer.WriteString(key)
|
||||
return buffer.String()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue