[feature] add paging to account follows, followers and follow requests endpoints (#2186)

This commit is contained in:
kim 2023-09-12 14:00:35 +01:00 committed by GitHub
commit 7293d6029b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
51 changed files with 2281 additions and 641 deletions

View file

@ -20,7 +20,9 @@ package bundb
import (
"strings"
"github.com/superseriousbusiness/gotosocial/internal/cache"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/paging"
"github.com/uptrace/bun"
)
@ -83,6 +85,29 @@ func whereStartsLike(
)
}
// loadPagedIDs loads a page of IDs from given SliceCache by `key`, resorting to `loadDESC` if required. Uses `page` to sort + page resulting IDs.
// NOTE: IDs returned from `cache` / `loadDESC` MUST be in descending order, otherwise paging will not work correctly / return things out of order.
func loadPagedIDs(cache *cache.SliceCache[string], key string, page *paging.Page, loadDESC func() ([]string, error)) ([]string, error) {
// Check cache for IDs, else load.
ids, err := cache.Load(key, loadDESC)
if err != nil {
return nil, err
}
// Our cached / selected IDs are ALWAYS
// fetched from `loadDESC` in descending
// order. Depending on the paging requested
// this may be an unexpected order.
if page.GetOrder().Ascending() {
ids = paging.Reverse(ids)
}
// Page the resulting IDs.
ids = page.Page(ids)
return ids, nil
}
// updateWhere parses []db.Where and adds it to the given update query.
func updateWhere(q *bun.UpdateQuery, where []db.Where) {
for _, w := range where {