From 3d776851082725a4e3b5780cd35bf888348b892f Mon Sep 17 00:00:00 2001 From: Thibault Chataigner Date: Mon, 6 Jun 2016 13:47:45 +0000 Subject: [PATCH] Enable the "limit" param in /api/search --- pkg/services/search/handlers.go | 1 + pkg/services/search/models.go | 1 + pkg/services/sqlstore/dashboard.go | 8 +++++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/services/search/handlers.go b/pkg/services/search/handlers.go index a4905d6fa58..a8344ba05a5 100644 --- a/pkg/services/search/handlers.go +++ b/pkg/services/search/handlers.go @@ -44,6 +44,7 @@ func searchHandler(query *Query) error { IsStarred: query.IsStarred, OrgId: query.OrgId, DashboardIds: query.DashboardIds, + Limit: query.Limit, } if err := bus.Dispatch(&dashQuery); err != nil { diff --git a/pkg/services/search/models.go b/pkg/services/search/models.go index 159637013f5..ada3e1ccdfa 100644 --- a/pkg/services/search/models.go +++ b/pkg/services/search/models.go @@ -42,6 +42,7 @@ type FindPersistedDashboardsQuery struct { UserId int64 IsStarred bool DashboardIds []int + Limit int Result HitList } diff --git a/pkg/services/sqlstore/dashboard.go b/pkg/services/sqlstore/dashboard.go index ef36fd75ab6..d71eaeefa6e 100644 --- a/pkg/services/sqlstore/dashboard.go +++ b/pkg/services/sqlstore/dashboard.go @@ -123,6 +123,11 @@ type DashboardSearchProjection struct { } func SearchDashboards(query *search.FindPersistedDashboardsQuery) error { + limit := query.Limit + if limit == 0 { + limit = 1000 + } + var sql bytes.Buffer params := make([]interface{}, 0) @@ -165,7 +170,8 @@ func SearchDashboards(query *search.FindPersistedDashboardsQuery) error { params = append(params, "%"+query.Title+"%") } - sql.WriteString(fmt.Sprintf(" ORDER BY dashboard.title ASC LIMIT 1000")) + sql.WriteString(fmt.Sprintf(" ORDER BY dashboard.title ASC LIMIT ?")) + params = append(params, limit) var res []DashboardSearchProjection