From 691854bd9c85bf4c77638062f9de15b5ff34defc Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Wed, 11 Sep 2024 15:50:29 +0200 Subject: [PATCH] more accurate search with checks --- pkg/services/dashboards/service/zanzana.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/services/dashboards/service/zanzana.go b/pkg/services/dashboards/service/zanzana.go index 21ed4abeea7..528a6492b0d 100644 --- a/pkg/services/dashboards/service/zanzana.go +++ b/pkg/services/dashboards/service/zanzana.go @@ -19,6 +19,7 @@ import ( const ( maxListQueryLength = 8 maxListQueryLimit = 100 + defaultQueryLimit = 1000 ) type searchResult struct { @@ -201,11 +202,15 @@ func (dr *DashboardServiceImpl) findDashboardsZanzanaCheck(ctx context.Context, defer span.End() query.SkipAccessControlFilter = true + // Set limit to default to prevent pagination issues + queryLimit := query.Limit + query.Limit = defaultQueryLimit findRes, err := dr.dashboardStore.FindDashboards(ctx, query) if err != nil { return nil, err } + query.Limit = queryLimit return dr.checkDashboards(ctx, query, findRes) } @@ -229,6 +234,9 @@ func (dr *DashboardServiceImpl) checkDashboards(ctx context.Context, query *dash go func() { defer wg.Done() for d := range resToCheck { + if len(allowedResults) >= int(query.Limit) { + return + } objectType := zanzana.TypeDashboard if d.IsFolder { objectType = zanzana.TypeFolder @@ -259,6 +267,9 @@ func (dr *DashboardServiceImpl) checkDashboards(ctx context.Context, query *dash wg.Wait() close(allowedResults) for r := range allowedResults { + if len(res) >= int(query.Limit) { + break + } res = append(res, r) }