mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-25 23:23:32 -06:00
[feature] add paging to account follows, followers and follow requests endpoints (#2186)
This commit is contained in:
parent
4b594516ec
commit
7293d6029b
51 changed files with 2281 additions and 641 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue