[chore] much improved paging package (#2182)

This commit is contained in:
kim 2023-09-07 15:58:37 +01:00 committed by GitHub
commit b093947d84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 1154 additions and 445 deletions

View file

@ -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)
}