diff options
author | 2023-09-07 15:58:37 +0100 | |
---|---|---|
committer | 2023-09-07 15:58:37 +0100 | |
commit | b093947d84127789e5a3a662a9e11d0b9438180e (patch) | |
tree | eec3be2f1594599bee3db90e737431708101ae45 /internal/db/bundb/relationship.go | |
parent | [feature] Support OTLP HTTP, drop Jaeger (#2184) (diff) | |
download | gotosocial-b093947d84127789e5a3a662a9e11d0b9438180e.tar.xz |
[chore] much improved paging package (#2182)
Diffstat (limited to 'internal/db/bundb/relationship.go')
-rw-r--r-- | internal/db/bundb/relationship.go | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/internal/db/bundb/relationship.go b/internal/db/bundb/relationship.go index 2f93b12ad..f1bdcf52b 100644 --- a/internal/db/bundb/relationship.go +++ b/internal/db/bundb/relationship.go @@ -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) } |