mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Folders: Include folder UID when loading dashboards for search v2 (#98592)
* Include folder UID when loading dashboards * Remove folder UID lookup
This commit is contained in:
parent
2fd355ebca
commit
e786292673
@ -42,18 +42,15 @@ type eventStore interface {
|
|||||||
GetAllEventsAfter(ctx context.Context, id int64) ([]*store.EntityEvent, error)
|
GetAllEventsAfter(ctx context.Context, id int64) ([]*store.EntityEvent, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// While we migrate away from internal IDs... this lets us lookup values in SQL
|
|
||||||
// NOTE: folderId is unique across all orgs
|
|
||||||
type folderUIDLookup = func(ctx context.Context, folderId int64) (string, error)
|
|
||||||
|
|
||||||
type dashboard struct {
|
type dashboard struct {
|
||||||
id int64
|
id int64
|
||||||
uid string
|
uid string
|
||||||
isFolder bool
|
isFolder bool
|
||||||
folderID int64
|
folderID int64
|
||||||
slug string
|
folderUID string
|
||||||
created time.Time
|
slug string
|
||||||
updated time.Time
|
created time.Time
|
||||||
|
updated time.Time
|
||||||
|
|
||||||
// Use generic structure
|
// Use generic structure
|
||||||
summary *entity.EntitySummary
|
summary *entity.EntitySummary
|
||||||
@ -99,14 +96,13 @@ type searchIndex struct {
|
|||||||
logger log.Logger
|
logger log.Logger
|
||||||
buildSignals chan buildSignal
|
buildSignals chan buildSignal
|
||||||
extender DocumentExtender
|
extender DocumentExtender
|
||||||
folderIdLookup folderUIDLookup
|
|
||||||
syncCh chan chan struct{}
|
syncCh chan chan struct{}
|
||||||
tracer tracing.Tracer
|
tracer tracing.Tracer
|
||||||
features featuremgmt.FeatureToggles
|
features featuremgmt.FeatureToggles
|
||||||
settings setting.SearchSettings
|
settings setting.SearchSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSearchIndex(dashLoader dashboardLoader, evStore eventStore, extender DocumentExtender, folderIDs folderUIDLookup, tracer tracing.Tracer, features featuremgmt.FeatureToggles, settings setting.SearchSettings) *searchIndex {
|
func newSearchIndex(dashLoader dashboardLoader, evStore eventStore, extender DocumentExtender, tracer tracing.Tracer, features featuremgmt.FeatureToggles, settings setting.SearchSettings) *searchIndex {
|
||||||
return &searchIndex{
|
return &searchIndex{
|
||||||
loader: dashLoader,
|
loader: dashLoader,
|
||||||
eventStore: evStore,
|
eventStore: evStore,
|
||||||
@ -115,7 +111,6 @@ func newSearchIndex(dashLoader dashboardLoader, evStore eventStore, extender Doc
|
|||||||
logger: log.New("searchIndex"),
|
logger: log.New("searchIndex"),
|
||||||
buildSignals: make(chan buildSignal),
|
buildSignals: make(chan buildSignal),
|
||||||
extender: extender,
|
extender: extender,
|
||||||
folderIdLookup: folderIDs,
|
|
||||||
syncCh: make(chan chan struct{}),
|
syncCh: make(chan chan struct{}),
|
||||||
tracer: tracer,
|
tracer: tracer,
|
||||||
features: features,
|
features: features,
|
||||||
@ -763,11 +758,7 @@ func (i *searchIndex) updateDashboard(ctx context.Context, orgID int64, index *o
|
|||||||
if dash.folderID == 0 {
|
if dash.folderID == 0 {
|
||||||
folderUID = folder.GeneralFolderUID
|
folderUID = folder.GeneralFolderUID
|
||||||
} else {
|
} else {
|
||||||
var err error
|
folderUID = dash.folderUID
|
||||||
folderUID, err = i.folderIdLookup(ctx, dash.folderID)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
location := folderUID
|
location := folderUID
|
||||||
@ -860,7 +851,7 @@ func (l sqlDashboardLoader) loadAllDashboards(ctx context.Context, limit int, or
|
|||||||
sess.Where("uid = ?", dashboardUID)
|
sess.Where("uid = ?", dashboardUID)
|
||||||
}
|
}
|
||||||
|
|
||||||
sess.Cols("id", "uid", "is_folder", "folder_id", "data", "slug", "created", "updated")
|
sess.Cols("id", "uid", "is_folder", "folder_id", "folder_uid", "data", "slug", "created", "updated")
|
||||||
|
|
||||||
sess.OrderBy("id ASC")
|
sess.OrderBy("id ASC")
|
||||||
sess.Limit(limit)
|
sess.Limit(limit)
|
||||||
@ -950,14 +941,15 @@ func (l sqlDashboardLoader) LoadDashboards(ctx context.Context, orgID int64, das
|
|||||||
// But append info anyway for now, since we possibly extracted useful information.
|
// But append info anyway for now, since we possibly extracted useful information.
|
||||||
}
|
}
|
||||||
dashboards = append(dashboards, dashboard{
|
dashboards = append(dashboards, dashboard{
|
||||||
id: row.Id,
|
id: row.Id,
|
||||||
uid: row.Uid,
|
uid: row.Uid,
|
||||||
isFolder: row.IsFolder,
|
isFolder: row.IsFolder,
|
||||||
folderID: row.FolderID,
|
folderID: row.FolderID,
|
||||||
slug: row.Slug,
|
folderUID: row.FolderUID,
|
||||||
created: row.Created,
|
slug: row.Slug,
|
||||||
updated: row.Updated,
|
created: row.Created,
|
||||||
summary: summary,
|
updated: row.Updated,
|
||||||
|
summary: summary,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
readDashboardSpan.End()
|
readDashboardSpan.End()
|
||||||
@ -966,30 +958,14 @@ func (l sqlDashboardLoader) LoadDashboards(ctx context.Context, orgID int64, das
|
|||||||
return dashboards, err
|
return dashboards, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFolderIDLookup(sql db.DB) folderUIDLookup {
|
|
||||||
return func(ctx context.Context, folderID int64) (string, error) {
|
|
||||||
uid := ""
|
|
||||||
err := sql.WithDbSession(ctx, func(sess *db.Session) error {
|
|
||||||
res, err := sess.Query("SELECT uid FROM dashboard WHERE id=?", folderID)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if len(res) > 0 {
|
|
||||||
uid = string(res[0]["uid"])
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
return uid, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type dashboardQueryResult struct {
|
type dashboardQueryResult struct {
|
||||||
Id int64
|
Id int64
|
||||||
Uid string
|
Uid string
|
||||||
IsFolder bool `xorm:"is_folder"`
|
IsFolder bool `xorm:"is_folder"`
|
||||||
FolderID int64 `xorm:"folder_id"`
|
FolderID int64 `xorm:"folder_id"`
|
||||||
Slug string `xorm:"slug"`
|
FolderUID string `xorm:"folder_uid"`
|
||||||
Data []byte
|
Slug string `xorm:"slug"`
|
||||||
Created time.Time
|
Data []byte
|
||||||
Updated time.Time
|
Created time.Time
|
||||||
|
Updated time.Time
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ func initTestIndexFromDashesExtended(t *testing.T, dashboards []dashboard, exten
|
|||||||
dashboardLoader := &testDashboardLoader{
|
dashboardLoader := &testDashboardLoader{
|
||||||
dashboards: dashboards,
|
dashboards: dashboards,
|
||||||
}
|
}
|
||||||
index := newSearchIndex(dashboardLoader, &store.MockEntityEventsService{}, extender, func(ctx context.Context, folderId int64) (string, error) { return "x", nil }, tracing.InitializeTracerForTest(), featuremgmt.WithFeatures(), setting.SearchSettings{})
|
index := newSearchIndex(dashboardLoader, &store.MockEntityEventsService{}, extender, tracing.InitializeTracerForTest(), featuremgmt.WithFeatures(), setting.SearchSettings{})
|
||||||
require.NotNil(t, index)
|
require.NotNil(t, index)
|
||||||
numDashboards, err := index.buildOrgIndex(context.Background(), testOrgID)
|
numDashboards, err := index.buildOrgIndex(context.Background(), testOrgID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -432,9 +432,10 @@ var dashboardsWithFolders = []dashboard{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 2,
|
id: 2,
|
||||||
uid: "2",
|
uid: "2",
|
||||||
folderID: 1,
|
folderID: 1,
|
||||||
|
folderUID: "1",
|
||||||
summary: &entity.EntitySummary{
|
summary: &entity.EntitySummary{
|
||||||
Name: "Dashboard in folder 1",
|
Name: "Dashboard in folder 1",
|
||||||
Nested: []*entity.EntitySummary{
|
Nested: []*entity.EntitySummary{
|
||||||
@ -444,9 +445,10 @@ var dashboardsWithFolders = []dashboard{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 3,
|
id: 3,
|
||||||
uid: "3",
|
uid: "3",
|
||||||
folderID: 1,
|
folderID: 1,
|
||||||
|
folderUID: "1",
|
||||||
summary: &entity.EntitySummary{
|
summary: &entity.EntitySummary{
|
||||||
Name: "Dashboard in folder 2",
|
Name: "Dashboard in folder 2",
|
||||||
Nested: []*entity.EntitySummary{
|
Nested: []*entity.EntitySummary{
|
||||||
|
@ -102,7 +102,6 @@ func ProvideService(cfg *setting.Cfg, sql db.DB, entityEventStore store.EntityEv
|
|||||||
newSQLDashboardLoader(sql, tracer, cfg.Search),
|
newSQLDashboardLoader(sql, tracer, cfg.Search),
|
||||||
entityEventStore,
|
entityEventStore,
|
||||||
extender.GetDocumentExtender(),
|
extender.GetDocumentExtender(),
|
||||||
newFolderIDLookup(sql),
|
|
||||||
tracer,
|
tracer,
|
||||||
features,
|
features,
|
||||||
cfg.Search,
|
cfg.Search,
|
||||||
|
Loading…
Reference in New Issue
Block a user