mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 14:42:24 -05:00
[chore] much improved paging package (#2182)
This commit is contained in:
parent
14ef098099
commit
b093947d84
15 changed files with 1154 additions and 445 deletions
25
internal/cache/slice.go
vendored
25
internal/cache/slice.go
vendored
|
|
@ -49,28 +49,3 @@ func (c *SliceCache[T]) Load(key string, load func() ([]T, error)) ([]T, error)
|
|||
// Return data clone for safety.
|
||||
return slices.Clone(data), nil
|
||||
}
|
||||
|
||||
// LoadRange is functionally the same as .Load(), but will pass the result through provided reslice function before returning a cloned result.
|
||||
func (c *SliceCache[T]) LoadRange(key string, load func() ([]T, error), reslice func([]T) []T) ([]T, error) {
|
||||
// Look for follow IDs list in cache under this key.
|
||||
data, ok := c.Get(key)
|
||||
|
||||
if !ok {
|
||||
var err error
|
||||
|
||||
// Not cached, load!
|
||||
data, err = load()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Store the data.
|
||||
c.Set(key, data)
|
||||
}
|
||||
|
||||
// Reslice to range.
|
||||
slice := reslice(data)
|
||||
|
||||
// Return range clone for safety.
|
||||
return slices.Clone(slice), nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue