Files
grafana/pkg/services/queryhistory/queryhistory_details.go
Piotr Jamróz 6750e881e3 Query History: Use a search index on new queries to filter in mixed data sources (#88979)
* Add search index table

* Stab a test

* Add more tests

* Add basic index

* Switch to UID and add a test for the index

* Improve tests coverage

* Remove redundant whitespaces

* Load all data source APIs when query history is loaded

* Fix column type

* Fix migration

* Clean-up the index

* Fix linting

* Fix migrations

* Fix migrations

* Fix migrations

* Rename index to details
2024-07-16 11:47:21 +02:00

37 lines
628 B
Go

package queryhistory
import (
"encoding/json"
"slices"
"github.com/grafana/grafana/pkg/components/simplejson"
)
type DataQuery struct {
Datasource Datasource `json:"datasource"`
}
func FindDataSourceUIDs(queriesJSON *simplejson.Json) ([]string, error) {
uids := make([]string, 0)
queries := []DataQuery{}
bytes, err := queriesJSON.ToDB()
if err != nil {
return uids, err
}
err = json.Unmarshal(bytes, &queries)
if err != nil {
return uids, err
}
for _, query := range queries {
if !slices.Contains(uids, query.Datasource.UID) {
uids = append(uids, query.Datasource.UID)
}
}
return uids, nil
}