diff options
| author | 2025-08-21 16:41:50 +0200 | |
|---|---|---|
| committer | 2025-08-21 16:41:50 +0200 | |
| commit | a79f83cbded3fb1165b338ce316dc9f2217467ff (patch) | |
| tree | 4b4a2b7084aced51c0a691cee6352b4ecae90df8 /internal/cache | |
| parent | [chore] bump golangci-lint version in CI, disable var-naming package name che... (diff) | |
| download | gotosocial-a79f83cbded3fb1165b338ce316dc9f2217467ff.tar.xz | |
[chore] update dependencies (#4386)
- codeberg.org/gruf/go-bytesize v1.0.3 -> v1.0.4
- codeberg.org/gruf/go-kv/v2 v2.0.6 -> v2.0.7
- codeberg.org/gruf/go-mutexes v1.5.2 -> v1.5.3
- codeberg.org/gruf/go-structr v0.9.7 -> v0.9.8
- codeberg.org/gruf/go-ffmpreg v0.6.8 -> v0.6.9
- github.com/tomnomnom/linkheader HEAD@2018 -> HEAD@2025
all of the above codeberg.org/gruf updates are in preparation for Go1.25, except for bytesize, and also ffmpreg which is a rebuild with the latest version of ffmpeg (v5.1.7)
Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4386
Co-authored-by: kim <grufwub@gmail.com>
Co-committed-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/cache')
| -rw-r--r-- | internal/cache/timeline/status.go | 37 | ||||
| -rw-r--r-- | internal/cache/wrappers.go | 63 |
2 files changed, 42 insertions, 58 deletions
diff --git a/internal/cache/timeline/status.go b/internal/cache/timeline/status.go index 59c339c91..6fe16c4a9 100644 --- a/internal/cache/timeline/status.go +++ b/internal/cache/timeline/status.go @@ -586,6 +586,9 @@ func (t *StatusTimeline) InsertOne(status *gtsmodel.Status, prepared *apimodel.S // status ID, including those that may be a boost of the given status. func (t *StatusTimeline) RemoveByStatusIDs(statusIDs ...string) { keys := make([]structr.Key, len(statusIDs)) + if len(keys) != len(statusIDs) { + panic(gtserror.New("BCE")) + } // Nil check indices outside loops. if t.idx_ID == nil || @@ -595,17 +598,12 @@ func (t *StatusTimeline) RemoveByStatusIDs(statusIDs ...string) { // Convert statusIDs to index keys. for i, id := range statusIDs { - keys[i] = t.idx_ID.Key(id) + keys[i] = structr.MakeKey(id) } // Invalidate all cached entries with IDs. t.cache.Invalidate(t.idx_ID, keys...) - // Convert statusIDs to index keys. - for i, id := range statusIDs { - keys[i] = t.idx_BoostOfID.Key(id) - } - // Invalidate all cached entries as boost of IDs. t.cache.Invalidate(t.idx_BoostOfID, keys...) } @@ -614,6 +612,9 @@ func (t *StatusTimeline) RemoveByStatusIDs(statusIDs ...string) { // account ID, including those that may be boosted by account ID. func (t *StatusTimeline) RemoveByAccountIDs(accountIDs ...string) { keys := make([]structr.Key, len(accountIDs)) + if len(keys) != len(accountIDs) { + panic(gtserror.New("BCE")) + } // Nil check indices outside loops. if t.idx_AccountID == nil || @@ -623,17 +624,12 @@ func (t *StatusTimeline) RemoveByAccountIDs(accountIDs ...string) { // Convert accountIDs to index keys. for i, id := range accountIDs { - keys[i] = t.idx_AccountID.Key(id) + keys[i] = structr.MakeKey(id) } // Invalidate all cached entries as by IDs. t.cache.Invalidate(t.idx_AccountID, keys...) - // Convert accountIDs to index keys. - for i, id := range accountIDs { - keys[i] = t.idx_BoostOfAccountID.Key(id) - } - // Invalidate all cached entries as boosted by IDs. t.cache.Invalidate(t.idx_BoostOfAccountID, keys...) } @@ -642,6 +638,9 @@ func (t *StatusTimeline) RemoveByAccountIDs(accountIDs ...string) { // timeline entries pertaining to status ID, including boosts of given status. func (t *StatusTimeline) UnprepareByStatusIDs(statusIDs ...string) { keys := make([]structr.Key, len(statusIDs)) + if len(keys) != len(statusIDs) { + panic(gtserror.New("BCE")) + } // Nil check indices outside loops. if t.idx_ID == nil || @@ -651,7 +650,7 @@ func (t *StatusTimeline) UnprepareByStatusIDs(statusIDs ...string) { // Convert statusIDs to index keys. for i, id := range statusIDs { - keys[i] = t.idx_ID.Key(id) + keys[i] = structr.MakeKey(id) } // Unprepare all statuses stored under StatusMeta.ID. @@ -659,11 +658,6 @@ func (t *StatusTimeline) UnprepareByStatusIDs(statusIDs ...string) { meta.prepared = nil } - // Convert statusIDs to index keys. - for i, id := range statusIDs { - keys[i] = t.idx_BoostOfID.Key(id) - } - // Unprepare all statuses stored under StatusMeta.BoostOfID. for meta := range t.cache.RangeKeysUnsafe(t.idx_BoostOfID, keys...) { meta.prepared = nil @@ -683,7 +677,7 @@ func (t *StatusTimeline) UnprepareByAccountIDs(accountIDs ...string) { // Convert accountIDs to index keys. for i, id := range accountIDs { - keys[i] = t.idx_AccountID.Key(id) + keys[i] = structr.MakeKey(id) } // Unprepare all statuses stored under StatusMeta.AccountID. @@ -691,11 +685,6 @@ func (t *StatusTimeline) UnprepareByAccountIDs(accountIDs ...string) { meta.prepared = nil } - // Convert accountIDs to index keys. - for i, id := range accountIDs { - keys[i] = t.idx_BoostOfAccountID.Key(id) - } - // Unprepare all statuses stored under StatusMeta.BoostOfAccountID. for meta := range t.cache.RangeKeysUnsafe(t.idx_BoostOfAccountID, keys...) { meta.prepared = nil diff --git a/internal/cache/wrappers.go b/internal/cache/wrappers.go index 34d7cb8db..6e3175b69 100644 --- a/internal/cache/wrappers.go +++ b/internal/cache/wrappers.go @@ -20,6 +20,7 @@ package cache import ( "slices" + "code.superseriousbusiness.org/gotosocial/internal/gtserror" "codeberg.org/gruf/go-cache/v3/simple" "codeberg.org/gruf/go-structr" ) @@ -86,22 +87,19 @@ func (c *StructCache[T]) Init(config structr.CacheConfig[T]) { // GetOne calls structr.Cache{}.GetOne(), using a cached structr.Index{} by 'index' name. // Note: this also handles conversion of the untyped (any) keys to structr.Key{} via structr.Index{}. func (c *StructCache[T]) GetOne(index string, key ...any) (T, bool) { - i := c.index[index] - return c.Cache.GetOne(i, i.Key(key...)) + return c.Cache.GetOne(c.index[index], structr.MakeKey(key...)) } // Get calls structr.Cache{}.Get(), using a cached structr.Index{} by 'index' name. // Note: this also handles conversion of the untyped (any) keys to structr.Key{} via structr.Index{}. func (c *StructCache[T]) Get(index string, keys ...[]any) []T { - i := c.index[index] - return c.Cache.Get(i, i.Keys(keys...)...) + return c.Cache.Get(c.index[index], structr.MakeKeys(keys...)...) } // LoadOne calls structr.Cache{}.LoadOne(), using a cached structr.Index{} by 'index' name. // Note: this also handles conversion of the untyped (any) keys to structr.Key{} via structr.Index{}. func (c *StructCache[T]) LoadOne(index string, load func() (T, error), key ...any) (T, error) { - i := c.index[index] - return c.Cache.LoadOne(i, i.Key(key...), load) + return c.Cache.LoadOne(c.index[index], structr.MakeKey(key...), load) } // LoadIDs calls structr.Cache{}.Load(), using a cached structr.Index{} by 'index' name. Note: this also handles @@ -109,28 +107,26 @@ func (c *StructCache[T]) LoadOne(index string, load func() (T, error), key ...an // // If you need to load multiple cache keys other than by ID strings, please create another convenience wrapper. func (c *StructCache[T]) LoadIDs(index string, ids []string, load func([]string) ([]T, error)) ([]T, error) { - i := c.index[index] - if i == nil { - // we only perform this check here as - // we're going to use the index before - // passing it to cache in main .Load(). - panic("missing index for cache type") - } // Generate cache keys for ID types. keys := make([]structr.Key, len(ids)) + if len(keys) != len(ids) { + panic(gtserror.New("BCE")) + } for x, id := range ids { - keys[x] = i.Key(id) + keys[x] = structr.MakeKey(id) } - // Pass loader callback with wrapper onto main cache load function. - return c.Cache.Load(i, keys, func(uncached []structr.Key) ([]T, error) { - uncachedIDs := make([]string, len(uncached)) - for i := range uncached { - uncachedIDs[i] = uncached[i].Values()[0].(string) - } - return load(uncachedIDs) - }) + // Pass loader callback with + // wrapper onto main cache load function. + return c.Cache.Load(c.index[index], keys, + func(uncached []structr.Key) ([]T, error) { + uncachedIDs := make([]string, len(uncached)) + for i := range uncached { + uncachedIDs[i] = uncached[i].Values()[0].(string) + } + return load(uncachedIDs) + }) } // LoadIDs2Part works as LoadIDs, except using a two-part key, @@ -147,8 +143,11 @@ func (c *StructCache[T]) LoadIDs2Part(index string, id1 string, id2s []string, l // Generate cache keys for two-part IDs. keys := make([]structr.Key, len(id2s)) + if len(keys) != len(id2s) { + panic(gtserror.New("BCE")) + } for x, id2 := range id2s { - keys[x] = i.Key(id1, id2) + keys[x] = structr.MakeKey(id1, id2) } // Pass loader callback with wrapper onto main cache load function. @@ -164,8 +163,7 @@ func (c *StructCache[T]) LoadIDs2Part(index string, id1 string, id2s []string, l // Invalidate calls structr.Cache{}.Invalidate(), using a cached structr.Index{} by 'index' name. // Note: this also handles conversion of the untyped (any) keys to structr.Key{} via structr.Index{}. func (c *StructCache[T]) Invalidate(index string, key ...any) { - i := c.index[index] - c.Cache.Invalidate(i, i.Key(key...)) + c.Cache.Invalidate(c.index[index], structr.MakeKey(key...)) } // InvalidateIDs calls structr.Cache{}.Invalidate(), using a cached structr.Index{} by 'index' name. Note: this also @@ -173,20 +171,17 @@ func (c *StructCache[T]) Invalidate(index string, key ...any) { // // If you need to invalidate multiple cache keys other than by ID strings, please create another convenience wrapper. func (c *StructCache[T]) InvalidateIDs(index string, ids []string) { - i := c.index[index] - if i == nil { - // we only perform this check here as - // we're going to use the index before - // passing it to cache in main .Load(). - panic("missing index for cache type") - } // Generate cache keys for ID types. keys := make([]structr.Key, len(ids)) + if len(keys) != len(ids) { + panic(gtserror.New("BCE")) + } for x, id := range ids { - keys[x] = i.Key(id) + keys[x] = structr.MakeKey(id) } // Pass to main invalidate func. - c.Cache.Invalidate(i, keys...) + c.Cache.Invalidate(c.index[index], + keys...) } |
