[v9.0.x] Search (SQL): support dashboardUID query parameter (#50126)
* Search (SQL): support dashboardUID query parameter (#50121)
(cherry picked from commit d452322aa8)
* manual merge
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
co-authored by
Ryan McKinley
parent
d5e9967809
commit
e674c9a2d1
@@ -75,8 +75,10 @@ func (ss *SQLStore) FindDashboards(ctx context.Context, query *models.FindPersis
|
||||
filters = append(filters, searchstore.TagsFilter{Tags: query.Tags})
|
||||
}
|
||||
|
||||
if len(query.DashboardIds) > 0 {
|
||||
filters = append(filters, searchstore.DashboardFilter{IDs: query.DashboardIds})
|
||||
if len(query.DashboardUIDs) > 0 {
|
||||
filters = append(filters, searchstore.DashboardFilter{UIDs: query.DashboardUIDs})
|
||||
} else if len(query.DashboardIds) > 0 {
|
||||
filters = append(filters, searchstore.DashboardIDFilter{IDs: query.DashboardIds})
|
||||
}
|
||||
|
||||
if query.IsStarred {
|
||||
|
||||
@@ -95,14 +95,22 @@ func (f FolderFilter) Where() (string, []interface{}) {
|
||||
return sqlIDin("dashboard.folder_id", f.IDs)
|
||||
}
|
||||
|
||||
type DashboardFilter struct {
|
||||
type DashboardIDFilter struct {
|
||||
IDs []int64
|
||||
}
|
||||
|
||||
func (f DashboardFilter) Where() (string, []interface{}) {
|
||||
func (f DashboardIDFilter) Where() (string, []interface{}) {
|
||||
return sqlIDin("dashboard.id", f.IDs)
|
||||
}
|
||||
|
||||
type DashboardFilter struct {
|
||||
UIDs []string
|
||||
}
|
||||
|
||||
func (f DashboardFilter) Where() (string, []interface{}) {
|
||||
return sqlUIDin("dashboard.uid", f.UIDs)
|
||||
}
|
||||
|
||||
type TagsFilter struct {
|
||||
Tags []string
|
||||
}
|
||||
@@ -150,6 +158,21 @@ func sqlIDin(column string, ids []int64) (string, []interface{}) {
|
||||
return fmt.Sprintf("%s IN %s", column, sqlArray), params
|
||||
}
|
||||
|
||||
func sqlUIDin(column string, uids []string) (string, []interface{}) {
|
||||
length := len(uids)
|
||||
if length < 1 {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
sqlArray := "(?" + strings.Repeat(",?", length-1) + ")"
|
||||
|
||||
params := []interface{}{}
|
||||
for _, id := range uids {
|
||||
params = append(params, id)
|
||||
}
|
||||
return fmt.Sprintf("%s IN %s", column, sqlArray), params
|
||||
}
|
||||
|
||||
// FolderWithAlertsFilter applies a filter that makes the result contain only folders that contain alert rules
|
||||
type FolderWithAlertsFilter struct {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user