mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-18 13:27:28 -06: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
|
|
@ -150,9 +150,9 @@ func (r *relationshipDB) GetAccountFollowRequesting(ctx context.Context, account
|
|||
return r.GetFollowRequestsByIDs(ctx, followReqIDs)
|
||||
}
|
||||
|
||||
func (r *relationshipDB) GetAccountBlocks(ctx context.Context, accountID string, page *paging.Pager) ([]*gtsmodel.Block, error) {
|
||||
func (r *relationshipDB) GetAccountBlocks(ctx context.Context, accountID string, page *paging.Page) ([]*gtsmodel.Block, error) {
|
||||
// Load block IDs from cache with database loader callback.
|
||||
blockIDs, err := r.state.Caches.GTS.BlockIDs().LoadRange(accountID, func() ([]string, error) {
|
||||
blockIDs, err := r.state.Caches.GTS.BlockIDs().Load(accountID, func() ([]string, error) {
|
||||
var blockIDs []string
|
||||
|
||||
// Block IDs not in cache, perform DB query!
|
||||
|
|
@ -162,11 +162,22 @@ func (r *relationshipDB) GetAccountBlocks(ctx context.Context, accountID string,
|
|||
}
|
||||
|
||||
return blockIDs, nil
|
||||
}, page.PageDesc)
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Our cached / selected block IDs are
|
||||
// ALWAYS stored in descending order.
|
||||
// Depending on the paging requested
|
||||
// this may be an unexpected order.
|
||||
if !page.GetOrder().Ascending() {
|
||||
blockIDs = paging.Reverse(blockIDs)
|
||||
}
|
||||
|
||||
// Page the resulting block IDs.
|
||||
blockIDs = page.Page(blockIDs)
|
||||
|
||||
// Convert these IDs to full block objects.
|
||||
return r.GetBlocksByIDs(ctx, blockIDs)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue