MCPcopy
hub / github.com/pocketbase/pocketbase / checkCollectionRateLimit

Function checkCollectionRateLimit

apis/middlewares_rate_limit.go:81–108  ·  view source on GitHub ↗

checkCollectionRateLimit checks whether the current request satisfy the rate limit configuration for the specific collection. Each baseTags entry will be prefixed with the collection name and its wildcard variant.

(e *core.RequestEvent, collection *core.Collection, baseTags ...string)

Source from the content-addressed store, hash-verified

79//
80// Each baseTags entry will be prefixed with the collection name and its wildcard variant.
81func checkCollectionRateLimit(e *core.RequestEvent, collection *core.Collection, baseTags ...string) error {
82 if skipRateLimit(e) {
83 return nil
84 }
85
86 labels := make([]string, 0, 2+len(baseTags)*2)
87
88 rtId := collection.Id + e.Request.Pattern
89
90 // add first the primary labels (aka. ["collectionName:action1", "collectionName:action2"])
91 for _, baseTag := range baseTags {
92 rtId += baseTag
93 labels = append(labels, collection.Name+":"+baseTag)
94 }
95
96 // add the wildcard labels (aka. [..., "*:action1","*:action2", "*"])
97 for _, baseTag := range baseTags {
98 labels = append(labels, "*:"+baseTag)
99 }
100 labels = append(labels, defaultRateLimitLabels(e)...)
101
102 rule, ok := e.App.Settings().RateLimits.FindRateLimitRule(labels, defaultRateLimitAudience(e)...)
103 if ok {
104 return checkRateLimit(e, rtId+rule.Audience, rule)
105 }
106
107 return nil
108}
109
110// isIPInList checks if the specified IP is in a list of other individual IPs or subnets.
111func isIPInList(ipsOrSubnets []string, ip string) bool {

Callers 6

recordsListFunction · 0.85
recordViewFunction · 0.85
recordCreateFunction · 0.85
recordUpdateFunction · 0.85
recordDeleteFunction · 0.85
collectionPathRateLimitFunction · 0.85

Calls 6

skipRateLimitFunction · 0.85
defaultRateLimitLabelsFunction · 0.85
defaultRateLimitAudienceFunction · 0.85
checkRateLimitFunction · 0.85
FindRateLimitRuleMethod · 0.80
SettingsMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…