summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-cache/v3/result/key.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2023-11-30 16:22:34 +0000
committerLibravatar GitHub <noreply@github.com>2023-11-30 16:22:34 +0000
commiteb170003b81504ba6eb85f950c223dc9eaf1cfca (patch)
treef1f9779e14875faa70f4db85a8cf19100633884d /vendor/codeberg.org/gruf/go-cache/v3/result/key.go
parent[bugfix] always go through status parent dereferencing on isNew, even on data... (diff)
downloadgotosocial-eb170003b81504ba6eb85f950c223dc9eaf1cfca.tar.xz
[bugfix] return 400 Bad Request on more cases of malformed AS data (#2399)
Diffstat (limited to 'vendor/codeberg.org/gruf/go-cache/v3/result/key.go')
-rw-r--r--vendor/codeberg.org/gruf/go-cache/v3/result/key.go23
1 files changed, 15 insertions, 8 deletions
diff --git a/vendor/codeberg.org/gruf/go-cache/v3/result/key.go b/vendor/codeberg.org/gruf/go-cache/v3/result/key.go
index 5e10e6fa1..5508936ba 100644
--- a/vendor/codeberg.org/gruf/go-cache/v3/result/key.go
+++ b/vendor/codeberg.org/gruf/go-cache/v3/result/key.go
@@ -43,9 +43,8 @@ func (sk structKeys) generate(a any) []cacheKey {
v = v.Elem()
}
- // Acquire byte buffer
+ // Acquire buffer
buf := getBuf()
- defer putBuf(buf)
outer:
for i := range sk {
@@ -80,6 +79,9 @@ outer:
})
}
+ // Release buf
+ putBuf(buf)
+
return keys
}
@@ -124,11 +126,12 @@ type structKey struct {
unique bool
// fields is a slice of runtime struct field
- // indices, of the fields encompassed by this key.
+ // indices, of fields encompassed by this key.
fields []structField
// pkeys is a lookup of stored struct key values
- // to the primary cache lookup key (int64).
+ // to the primary cache lookup key (int64). this
+ // is protected by the main cache mutex.
pkeys map[string][]int64
}
@@ -192,9 +195,8 @@ func (sk *structKey) genKey(parts []any) string {
panic(fmt.Sprintf("incorrect no. key parts provided: want=%d received=%d", len(parts), len(sk.fields)))
}
- // Acquire byte buffer
+ // Acquire buffer
buf := getBuf()
- defer putBuf(buf)
buf.Reset()
for i, part := range parts {
@@ -210,8 +212,13 @@ func (sk *structKey) genKey(parts []any) string {
// Drop last '.'
buf.Truncate(1)
- // Return string copy
- return string(buf.B)
+ // Create str copy
+ str := string(buf.B)
+
+ // Release buf
+ putBuf(buf)
+
+ return str
}
type structField struct {