mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-16 15:33:02 -06:00
[performance] add caching of status fave, boost of, in reply to ID lists (#2060)
This commit is contained in:
parent
00adf18c24
commit
9a291dea84
27 changed files with 610 additions and 406 deletions
16
vendor/codeberg.org/gruf/go-cache/v3/simple/cache.go
generated
vendored
16
vendor/codeberg.org/gruf/go-cache/v3/simple/cache.go
generated
vendored
|
|
@ -102,7 +102,7 @@ func (c *Cache[K, V]) Add(key K, value V) bool {
|
|||
}
|
||||
|
||||
// Alloc new entry.
|
||||
new := getEntry()
|
||||
new := GetEntry()
|
||||
new.Key = key
|
||||
new.Value = value
|
||||
|
||||
|
|
@ -111,7 +111,7 @@ func (c *Cache[K, V]) Add(key K, value V) bool {
|
|||
evcK = item.Key.(K)
|
||||
evcV = item.Value.(V)
|
||||
ev = true
|
||||
putEntry(item)
|
||||
PutEntry(item)
|
||||
})
|
||||
|
||||
// Set hook func ptr.
|
||||
|
|
@ -161,7 +161,7 @@ func (c *Cache[K, V]) Set(key K, value V) {
|
|||
item.Value = value
|
||||
} else {
|
||||
// Alloc new entry.
|
||||
new := getEntry()
|
||||
new := GetEntry()
|
||||
new.Key = key
|
||||
new.Value = value
|
||||
|
||||
|
|
@ -170,7 +170,7 @@ func (c *Cache[K, V]) Set(key K, value V) {
|
|||
evcK = item.Key.(K)
|
||||
evcV = item.Value.(V)
|
||||
ev = true
|
||||
putEntry(item)
|
||||
PutEntry(item)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -311,7 +311,7 @@ func (c *Cache[K, V]) Invalidate(key K) (ok bool) {
|
|||
_ = c.Cache.Delete(key)
|
||||
|
||||
// Free entry
|
||||
putEntry(item)
|
||||
PutEntry(item)
|
||||
|
||||
// Set hook func ptrs.
|
||||
invalid = c.Invalid
|
||||
|
|
@ -367,7 +367,7 @@ func (c *Cache[K, V]) InvalidateAll(keys ...K) (ok bool) {
|
|||
invalid(k, v)
|
||||
|
||||
// Free this entry.
|
||||
putEntry(items[x])
|
||||
PutEntry(items[x])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -410,7 +410,7 @@ func (c *Cache[K, V]) Trim(perc float64) {
|
|||
invalid(k, v)
|
||||
|
||||
// Free this entry.
|
||||
putEntry(items[x])
|
||||
PutEntry(items[x])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -438,7 +438,7 @@ func (c *Cache[K, V]) locked(fn func()) {
|
|||
func (c *Cache[K, V]) truncate(sz int, hook func(K, V)) []*Entry {
|
||||
if hook == nil {
|
||||
// No hook to execute, simply release all truncated entries.
|
||||
c.Cache.Truncate(sz, func(_ K, item *Entry) { putEntry(item) })
|
||||
c.Cache.Truncate(sz, func(_ K, item *Entry) { PutEntry(item) })
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
8
vendor/codeberg.org/gruf/go-cache/v3/simple/pool.go
generated
vendored
8
vendor/codeberg.org/gruf/go-cache/v3/simple/pool.go
generated
vendored
|
|
@ -6,8 +6,8 @@ import "sync"
|
|||
// objects, regardless of cache type.
|
||||
var entryPool sync.Pool
|
||||
|
||||
// getEntry fetches an Entry from pool, or allocates new.
|
||||
func getEntry() *Entry {
|
||||
// GetEntry fetches an Entry from pool, or allocates new.
|
||||
func GetEntry() *Entry {
|
||||
v := entryPool.Get()
|
||||
if v == nil {
|
||||
return new(Entry)
|
||||
|
|
@ -15,8 +15,8 @@ func getEntry() *Entry {
|
|||
return v.(*Entry)
|
||||
}
|
||||
|
||||
// putEntry replaces an Entry in the pool.
|
||||
func putEntry(e *Entry) {
|
||||
// PutEntry replaces an Entry in the pool.
|
||||
func PutEntry(e *Entry) {
|
||||
e.Key = nil
|
||||
e.Value = nil
|
||||
entryPool.Put(e)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue