From cbaeffde2c4013a3a9ff031fd17df74b272c621d Mon Sep 17 00:00:00 2001 From: Christoph Kluge Date: Mon, 22 Apr 2024 11:29:31 +0200 Subject: [PATCH] fix: improve speed of hasNextPage query for infinite scroll --- internal/graph/schema.resolvers.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/internal/graph/schema.resolvers.go b/internal/graph/schema.resolvers.go index a33e041..5f55139 100644 --- a/internal/graph/schema.resolvers.go +++ b/internal/graph/schema.resolvers.go @@ -243,14 +243,21 @@ func (r *queryResolver) Jobs(ctx context.Context, filter []*model.JobFilter, pag if !config.Keys.UiDefaults["job_list_usePaging"].(bool) { 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 { log.Warn("Error while querying next jobs") return nil, err } - if len(nextJobs) > 0 { + + if len(nextJobs) == 1 { hasNextPage = true }