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)
|
||||
}
|
||||
|
||||
// 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 {
|
||||
id int64
|
||||
uid string
|
||||
isFolder bool
|
||||
folderID int64
|
||||
slug string
|
||||
created time.Time
|
||||
updated time.Time
|
||||
id int64
|
||||
uid string
|
||||
isFolder bool
|
||||
folderID int64
|
||||
folderUID string
|
||||
slug string
|
||||
created time.Time
|
||||
updated time.Time
|
||||
|
||||
// Use generic structure
|
||||
summary *entity.EntitySummary
|
||||
@ -99,14 +96,13 @@ type searchIndex struct {
|
||||
logger log.Logger
|
||||
buildSignals chan buildSignal
|
||||
extender DocumentExtender
|
||||
folderIdLookup folderUIDLookup
|
||||
syncCh chan chan struct{}
|
||||
tracer tracing.Tracer
|
||||
features featuremgmt.FeatureToggles
|
||||
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{
|
||||
loader: dashLoader,
|
||||
eventStore: evStore,
|
||||
@ -115,7 +111,6 @@ func newSearchIndex(dashLoader dashboardLoader, evStore eventStore, extender Doc
|
||||
logger: log.New("searchIndex"),
|
||||
buildSignals: make(chan buildSignal),
|
||||
extender: extender,
|
||||
folderIdLookup: folderIDs,
|
||||
syncCh: make(chan chan struct{}),
|
||||
tracer: tracer,
|
||||
features: features,
|
||||
@ -763,11 +758,7 @@ func (i *searchIndex) updateDashboard(ctx context.Context, orgID int64, index *o
|
||||
if dash.folderID == 0 {
|
||||
folderUID = folder.GeneralFolderUID
|
||||
} else {
|
||||
var err error
|
||||
folderUID, err = i.folderIdLookup(ctx, dash.folderID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
folderUID = dash.folderUID
|
||||
}
|
||||
|
||||
location := folderUID
|
||||
@ -860,7 +851,7 @@ func (l sqlDashboardLoader) loadAllDashboards(ctx context.Context, limit int, or
|
||||
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.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.
|
||||
}
|
||||
dashboards = append(dashboards, dashboard{
|
||||
id: row.Id,
|
||||
uid: row.Uid,
|
||||
isFolder: row.IsFolder,
|
||||
folderID: row.FolderID,
|
||||
slug: row.Slug,
|
||||
created: row.Created,
|
||||
updated: row.Updated,
|
||||
summary: summary,
|
||||
id: row.Id,
|
||||
uid: row.Uid,
|
||||
isFolder: row.IsFolder,
|
||||
folderID: row.FolderID,
|
||||
folderUID: row.FolderUID,
|
||||
slug: row.Slug,
|
||||
created: row.Created,
|
||||
updated: row.Updated,
|
||||
summary: summary,
|
||||
})
|
||||
}
|
||||
readDashboardSpan.End()
|
||||
@ -966,30 +958,14 @@ func (l sqlDashboardLoader) LoadDashboards(ctx context.Context, orgID int64, das
|
||||
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 {
|
||||
Id int64
|
||||
Uid string
|
||||
IsFolder bool `xorm:"is_folder"`
|
||||
FolderID int64 `xorm:"folder_id"`
|
||||
Slug string `xorm:"slug"`
|
||||
Data []byte
|
||||
Created time.Time
|
||||
Updated time.Time
|
||||
Id int64
|
||||
Uid string
|
||||
IsFolder bool `xorm:"is_folder"`
|
||||
FolderID int64 `xorm:"folder_id"`
|
||||
FolderUID string `xorm:"folder_uid"`
|
||||
Slug string `xorm:"slug"`
|
||||
Data []byte
|
||||
Created time.Time
|
||||
Updated time.Time
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ func initTestIndexFromDashesExtended(t *testing.T, dashboards []dashboard, exten
|
||||
dashboardLoader := &testDashboardLoader{
|
||||
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)
|
||||
numDashboards, err := index.buildOrgIndex(context.Background(), testOrgID)
|
||||
require.NoError(t, err)
|
||||
@ -432,9 +432,10 @@ var dashboardsWithFolders = []dashboard{
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
uid: "2",
|
||||
folderID: 1,
|
||||
id: 2,
|
||||
uid: "2",
|
||||
folderID: 1,
|
||||
folderUID: "1",
|
||||
summary: &entity.EntitySummary{
|
||||
Name: "Dashboard in folder 1",
|
||||
Nested: []*entity.EntitySummary{
|
||||
@ -444,9 +445,10 @@ var dashboardsWithFolders = []dashboard{
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
uid: "3",
|
||||
folderID: 1,
|
||||
id: 3,
|
||||
uid: "3",
|
||||
folderID: 1,
|
||||
folderUID: "1",
|
||||
summary: &entity.EntitySummary{
|
||||
Name: "Dashboard in folder 2",
|
||||
Nested: []*entity.EntitySummary{
|
||||
|
@ -102,7 +102,6 @@ func ProvideService(cfg *setting.Cfg, sql db.DB, entityEventStore store.EntityEv
|
||||
newSQLDashboardLoader(sql, tracer, cfg.Search),
|
||||
entityEventStore,
|
||||
extender.GetDocumentExtender(),
|
||||
newFolderIDLookup(sql),
|
||||
tracer,
|
||||
features,
|
||||
cfg.Search,
|
||||
|
Loading…
Reference in New Issue
Block a user