summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-structr/cache.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-04-11 10:46:08 +0100
committerLibravatar GitHub <noreply@github.com>2024-04-11 11:46:08 +0200
commitdb2dcc3455e91aa3cc9599358d8eae4f0ef75b91 (patch)
treeb43016efd4f105634bd3ea04fe72417dadaca5e6 /vendor/codeberg.org/gruf/go-structr/cache.go
parent[feature] New user sign-up via web page (#2796) (diff)
downloadgotosocial-db2dcc3455e91aa3cc9599358d8eae4f0ef75b91.tar.xz
[chore] update go-structr => v0.6.2 (fixes nested field ptr following) (#2822)
* update go-structr => v0.6.1 (fixes nested field ptr following) * bump to v0.6.2
Diffstat (limited to 'vendor/codeberg.org/gruf/go-structr/cache.go')
-rw-r--r--vendor/codeberg.org/gruf/go-structr/cache.go25
1 files changed, 17 insertions, 8 deletions
diff --git a/vendor/codeberg.org/gruf/go-structr/cache.go b/vendor/codeberg.org/gruf/go-structr/cache.go
index 7b0772acf..9d5e7f912 100644
--- a/vendor/codeberg.org/gruf/go-structr/cache.go
+++ b/vendor/codeberg.org/gruf/go-structr/cache.go
@@ -255,18 +255,21 @@ func (c *Cache[T]) LoadOne(index *Index, key Key, load func() (T, error)) (T, er
item := index.get_one(key)
if ok = (item != nil); ok {
- if value, is := item.data.(T); is {
+ var is bool
+
+ if val, is = item.data.(T); is {
// Set value COPY.
- val = c.copy(value)
+ val = c.copy(val)
// Push to front of LRU list, USING
// THE ITEM'S LRU ENTRY, NOT THE
// INDEX KEY ENTRY. VERY IMPORTANT!!
c.lru.move_front(&item.elem)
- } else if error, is := item.data.(error); is {
- // Return error.
- err = error
+ } else {
+
+ // Attempt to return error.
+ err, _ = item.data.(error)
}
}
@@ -423,10 +426,10 @@ func (c *Cache[T]) Invalidate(index *Index, keys ...Key) {
// Preallocate expected ret slice.
values := make([]T, 0, len(keys))
- for i := range keys {
+ for _, key := range keys {
// Delete all items under key from index, collecting
// value items and dropping them from all their indices.
- index.delete(keys[i], func(item *indexed_item) {
+ index.delete(key, func(item *indexed_item) {
if value, ok := item.data.(T); ok {
// No need to copy, as item
@@ -524,6 +527,9 @@ func (c *Cache[T]) store_value(index *Index, key Key, value T) {
index.append(key, item)
}
+ // Get ptr to value data.
+ ptr := unsafe.Pointer(&value)
+
// Acquire key buf.
buf := new_buffer()
@@ -538,7 +544,10 @@ func (c *Cache[T]) store_value(index *Index, key Key, value T) {
}
// Extract fields comprising index key.
- parts := extract_fields(value, idx.fields)
+ parts := extract_fields(ptr, idx.fields)
+ if parts == nil {
+ continue
+ }
// Calculate index key.
key := idx.key(buf, parts)