[bugfix] Fix paging for empty items (#2236)

* use minID properly for public timeline

* return paged response properly even when 0 items

* use gtserror

* page more consistently (for now)

* test

* aaa
This commit is contained in:
tobi
2023-09-29 15:31:10 +02:00
committed by GitHub
parent 736cd37caf
commit 2b6b9cdf83
7 changed files with 75 additions and 62 deletions

View File

@ -19,6 +19,7 @@ package admin
import (
"context"
"errors"
"fmt"
"strconv"
"time"
@ -45,17 +46,20 @@ func (p *Processor) ReportsGet(
limit int,
) (*apimodel.PageableResponse, gtserror.WithCode) {
reports, err := p.state.DB.GetReports(ctx, resolved, accountID, targetAccountID, maxID, sinceID, minID, limit)
if err != nil {
if err == db.ErrNoEntries {
return util.EmptyPageableResponse(), nil
}
if err != nil && !errors.Is(err, db.ErrNoEntries) {
return nil, gtserror.NewErrorInternalError(err)
}
count := len(reports)
items := make([]interface{}, 0, count)
nextMaxIDValue := reports[count-1].ID
prevMinIDValue := reports[0].ID
if count == 0 {
return util.EmptyPageableResponse(), nil
}
var (
items = make([]interface{}, 0, count)
nextMaxIDValue = reports[count-1].ID
prevMinIDValue = reports[0].ID
)
for _, r := range reports {
item, err := p.converter.ReportToAdminAPIReport(ctx, r, account)
@ -65,7 +69,7 @@ func (p *Processor) ReportsGet(
items = append(items, item)
}
extraQueryParams := []string{}
extraQueryParams := make([]string, 0, 3)
if resolved != nil {
extraQueryParams = append(extraQueryParams, "resolved="+strconv.FormatBool(*resolved))
}