mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-12-22 18:22:11 +00:00
[bugfix] update cache library with nil ptr fix (#2070)
Signed-off-by: kim <grufwub@gmail.com>
This commit is contained in:
parent
7f1f2b80ea
commit
6f4ae8f58d
2
go.mod
2
go.mod
|
@ -5,7 +5,7 @@ go 1.20
|
|||
require (
|
||||
codeberg.org/gruf/go-bytesize v1.0.2
|
||||
codeberg.org/gruf/go-byteutil v1.1.2
|
||||
codeberg.org/gruf/go-cache/v3 v3.5.5
|
||||
codeberg.org/gruf/go-cache/v3 v3.5.6
|
||||
codeberg.org/gruf/go-debug v1.3.0
|
||||
codeberg.org/gruf/go-errors/v2 v2.2.0
|
||||
codeberg.org/gruf/go-fastcopy v1.1.2
|
||||
|
|
4
go.sum
4
go.sum
|
@ -48,8 +48,8 @@ codeberg.org/gruf/go-bytesize v1.0.2/go.mod h1:n/GU8HzL9f3UNp/mUKyr1qVmTlj7+xacp
|
|||
codeberg.org/gruf/go-byteutil v1.0.0/go.mod h1:cWM3tgMCroSzqoBXUXMhvxTxYJp+TbCr6ioISRY5vSU=
|
||||
codeberg.org/gruf/go-byteutil v1.1.2 h1:TQLZtTxTNca9xEfDIndmo7nBYxeS94nrv/9DS3Nk5Tw=
|
||||
codeberg.org/gruf/go-byteutil v1.1.2/go.mod h1:cWM3tgMCroSzqoBXUXMhvxTxYJp+TbCr6ioISRY5vSU=
|
||||
codeberg.org/gruf/go-cache/v3 v3.5.5 h1:Ce7odyvr8oF6h49LSjPL7AZs2QGyKMN9BPkgKcfR0BA=
|
||||
codeberg.org/gruf/go-cache/v3 v3.5.5/go.mod h1:NbsGQUgEdNFd631WSasvCHIVAaY9ovuiSeoBwtsIeDc=
|
||||
codeberg.org/gruf/go-cache/v3 v3.5.6 h1:TJnNOuij5DF/ZK9pDB61SlYzxidRQeYjYYW3dfFSznc=
|
||||
codeberg.org/gruf/go-cache/v3 v3.5.6/go.mod h1:NbsGQUgEdNFd631WSasvCHIVAaY9ovuiSeoBwtsIeDc=
|
||||
codeberg.org/gruf/go-debug v1.3.0 h1:PIRxQiWUFKtGOGZFdZ3Y0pqyfI0Xr87j224IYe2snZs=
|
||||
codeberg.org/gruf/go-debug v1.3.0/go.mod h1:N+vSy9uJBQgpQcJUqjctvqFz7tBHJf+S/PIjLILzpLg=
|
||||
codeberg.org/gruf/go-errors/v2 v2.0.0/go.mod h1:ZRhbdhvgoUA3Yw6e56kd9Ox984RrvbEFC2pOXyHDJP4=
|
||||
|
|
3
internal/cache/size.go
vendored
3
internal/cache/size.go
vendored
|
@ -157,12 +157,14 @@ func totalOfRatios() float64 {
|
|||
config.GetCacheAccountNoteMemRatio() +
|
||||
config.GetCacheBlockMemRatio() +
|
||||
config.GetCacheBlockIDsMemRatio() +
|
||||
config.GetCacheBoostOfIDsMemRatio() +
|
||||
config.GetCacheEmojiMemRatio() +
|
||||
config.GetCacheEmojiCategoryMemRatio() +
|
||||
config.GetCacheFollowMemRatio() +
|
||||
config.GetCacheFollowIDsMemRatio() +
|
||||
config.GetCacheFollowRequestMemRatio() +
|
||||
config.GetCacheFollowRequestIDsMemRatio() +
|
||||
config.GetCacheInReplyToIDsMemRatio() +
|
||||
config.GetCacheInstanceMemRatio() +
|
||||
config.GetCacheListMemRatio() +
|
||||
config.GetCacheListEntryMemRatio() +
|
||||
|
@ -173,6 +175,7 @@ func totalOfRatios() float64 {
|
|||
config.GetCacheReportMemRatio() +
|
||||
config.GetCacheStatusMemRatio() +
|
||||
config.GetCacheStatusFaveMemRatio() +
|
||||
config.GetCacheStatusFaveIDsMemRatio() +
|
||||
config.GetCacheTagMemRatio() +
|
||||
config.GetCacheTombstoneMemRatio() +
|
||||
config.GetCacheUserMemRatio() +
|
||||
|
|
36
vendor/codeberg.org/gruf/go-cache/v3/result/cache.go
generated
vendored
36
vendor/codeberg.org/gruf/go-cache/v3/result/cache.go
generated
vendored
|
@ -91,6 +91,7 @@ func (c *Cache[T]) SetEvictionCallback(hook func(T)) {
|
|||
|
||||
if res.Error != nil {
|
||||
// Skip value hooks
|
||||
putResult(res)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -119,6 +120,7 @@ func (c *Cache[T]) SetInvalidateCallback(hook func(T)) {
|
|||
|
||||
if res.Error != nil {
|
||||
// Skip value hooks
|
||||
putResult(res)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -147,10 +149,8 @@ func (c *Cache[T]) IgnoreErrors(ignore func(error) bool) {
|
|||
|
||||
// Load will attempt to load an existing result from the cacche for the given lookup and key parts, else calling the provided load function and caching the result.
|
||||
func (c *Cache[T]) Load(lookup string, load func() (T, error), keyParts ...any) (T, error) {
|
||||
var (
|
||||
zero T
|
||||
res *result
|
||||
)
|
||||
var zero T
|
||||
var res *result
|
||||
|
||||
// Get lookup key info by name.
|
||||
keyInfo := c.lookups.get(lookup)
|
||||
|
@ -164,12 +164,11 @@ func (c *Cache[T]) Load(lookup string, load func() (T, error), keyParts ...any)
|
|||
// Acquire cache lock
|
||||
c.cache.Lock()
|
||||
|
||||
// Look for primary cache key
|
||||
pkeys := keyInfo.pkeys[ckey]
|
||||
|
||||
if len(pkeys) > 0 {
|
||||
// Look for primary key for cache key (only accept len=1)
|
||||
if pkeys := keyInfo.pkeys[ckey]; len(pkeys) == 1 {
|
||||
// Fetch the result for primary key
|
||||
entry, ok := c.cache.Cache.Get(pkeys[0])
|
||||
|
||||
if ok {
|
||||
// Since the invalidation / eviction hooks acquire a mutex
|
||||
// lock separately, and only at this point are the pkeys
|
||||
|
@ -298,12 +297,11 @@ func (c *Cache[T]) Has(lookup string, keyParts ...any) bool {
|
|||
// Acquire cache lock
|
||||
c.cache.Lock()
|
||||
|
||||
// Look for primary key for cache key
|
||||
pkeys := keyInfo.pkeys[ckey]
|
||||
|
||||
if len(pkeys) > 0 {
|
||||
// Look for primary key for cache key (only accept len=1)
|
||||
if pkeys := keyInfo.pkeys[ckey]; len(pkeys) == 1 {
|
||||
// Fetch the result for primary key
|
||||
entry, ok := c.cache.Cache.Get(pkeys[0])
|
||||
|
||||
if ok {
|
||||
// Since the invalidation / eviction hooks acquire a mutex
|
||||
// lock separately, and only at this point are the pkeys
|
||||
|
@ -364,17 +362,25 @@ func (c *Cache[T]) store(res *result) (evict func()) {
|
|||
if key.info.unique && len(pkeys) > 0 {
|
||||
for _, conflict := range pkeys {
|
||||
// Get the overlapping result with this key.
|
||||
entry, _ := c.cache.Cache.Get(conflict)
|
||||
confRes := entry.Value.(*result)
|
||||
entry, ok := c.cache.Cache.Get(conflict)
|
||||
|
||||
if !ok {
|
||||
// Since the invalidation / eviction hooks acquire a mutex
|
||||
// lock separately, and only at this point are the pkeys
|
||||
// updated, there is a chance that a primary key may return
|
||||
// no matching entry. Hence we have to check for it here.
|
||||
continue
|
||||
}
|
||||
|
||||
// From conflicting entry, drop this key, this
|
||||
// will prevent eviction cleanup key confusion.
|
||||
confRes := entry.Value.(*result)
|
||||
confRes.Keys.drop(key.info.name)
|
||||
|
||||
if len(res.Keys) == 0 {
|
||||
// We just over-wrote the only lookup key for
|
||||
// this value, so we drop its primary key too.
|
||||
c.cache.Cache.Delete(conflict)
|
||||
_ = c.cache.Cache.Delete(conflict)
|
||||
|
||||
// Add finished result to evict queue.
|
||||
toEvict = append(toEvict, confRes)
|
||||
|
|
1
vendor/codeberg.org/gruf/go-cache/v3/result/pool.go
generated
vendored
1
vendor/codeberg.org/gruf/go-cache/v3/result/pool.go
generated
vendored
|
@ -17,6 +17,7 @@ func getResult() *result {
|
|||
|
||||
// putResult replaces a result in the pool.
|
||||
func putResult(r *result) {
|
||||
r.PKey = 0
|
||||
r.Keys = nil
|
||||
r.Value = nil
|
||||
r.Error = nil
|
||||
|
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
|
@ -13,7 +13,7 @@ codeberg.org/gruf/go-bytesize
|
|||
# codeberg.org/gruf/go-byteutil v1.1.2
|
||||
## explicit; go 1.16
|
||||
codeberg.org/gruf/go-byteutil
|
||||
# codeberg.org/gruf/go-cache/v3 v3.5.5
|
||||
# codeberg.org/gruf/go-cache/v3 v3.5.6
|
||||
## explicit; go 1.19
|
||||
codeberg.org/gruf/go-cache/v3
|
||||
codeberg.org/gruf/go-cache/v3/result
|
||||
|
|
Loading…
Reference in a new issue