fix: improve speed of hasNextPage query for infinite scroll

This commit is contained in:
Christoph Kluge 2024-04-22 11:29:31 +02:00
parent b67f5436f8
commit cbaeffde2c

View File

@ -243,14 +243,21 @@ func (r *queryResolver) Jobs(ctx context.Context, filter []*model.JobFilter, pag
if !config.Keys.UiDefaults["job_list_usePaging"].(bool) { if !config.Keys.UiDefaults["job_list_usePaging"].(bool) {
hasNextPage := false hasNextPage := false
page.Page += 1 // page.Page += 1 : Simple, but expensive
// Example Page 4 @ 10 IpP : Does item 41 exist?
// Minimal Page 41 @ 1 IpP : If len(result) is 1, Page 5 @ 10 IpP exists.
nextPage := &model.PageRequest{
ItemsPerPage: 1,
Page: ((page.Page * page.ItemsPerPage) + 1),
}
nextJobs, err := r.Repo.QueryJobs(ctx, filter, page, order) nextJobs, err := r.Repo.QueryJobs(ctx, filter, nextPage, order)
if err != nil { if err != nil {
log.Warn("Error while querying next jobs") log.Warn("Error while querying next jobs")
return nil, err return nil, err
} }
if len(nextJobs) > 0 {
if len(nextJobs) == 1 {
hasNextPage = true hasNextPage = true
} }