Commit d89c1260 by Daniel Lee

WIP: refactor dash search and remove extra query

parent 5cf40cbd
...@@ -148,12 +148,14 @@ func GetDashboard(query *m.GetDashboardQuery) error { ...@@ -148,12 +148,14 @@ func GetDashboard(query *m.GetDashboardQuery) error {
} }
type DashboardSearchProjection struct { type DashboardSearchProjection struct {
Id int64 Id int64
Title string Title string
Slug string Slug string
Term string Term string
IsFolder bool IsFolder bool
ParentId int64 ParentId int64
FolderSlug string
FolderTitle string
} }
func findDashboards(query *search.FindPersistedDashboardsQuery) ([]DashboardSearchProjection, error) { func findDashboards(query *search.FindPersistedDashboardsQuery) ([]DashboardSearchProjection, error) {
...@@ -167,9 +169,10 @@ func findDashboards(query *search.FindPersistedDashboardsQuery) ([]DashboardSear ...@@ -167,9 +169,10 @@ func findDashboards(query *search.FindPersistedDashboardsQuery) ([]DashboardSear
dashboard_tag.term, dashboard_tag.term,
dashboard.is_folder, dashboard.is_folder,
dashboard.parent_id, dashboard.parent_id,
pd.title as folder_title f.slug as folder_slug,
f.title as folder_title
FROM dashboard FROM dashboard
LEFT OUTER JOIN dashboard pd on pd.id = dashboard.parent_id LEFT OUTER JOIN dashboard f on f.id = dashboard.parent_id
LEFT OUTER JOIN dashboard_tag on dashboard_tag.dashboard_id = dashboard.id`) LEFT OUTER JOIN dashboard_tag on dashboard_tag.dashboard_id = dashboard.id`)
if query.IsStarred { if query.IsStarred {
...@@ -268,26 +271,13 @@ func SearchDashboards(query *search.FindPersistedDashboardsQuery) error { ...@@ -268,26 +271,13 @@ func SearchDashboards(query *search.FindPersistedDashboardsQuery) error {
// appends parent folders for any hits to the search result // appends parent folders for any hits to the search result
func appendDashboardFolders(res []DashboardSearchProjection) ([]DashboardSearchProjection, error) { func appendDashboardFolders(res []DashboardSearchProjection) ([]DashboardSearchProjection, error) {
var dashboardFolderIds []int64
for _, item := range res { for _, item := range res {
if item.ParentId > 0 { if item.ParentId > 0 {
dashboardFolderIds = append(dashboardFolderIds, item.ParentId)
}
}
if len(dashboardFolderIds) > 0 {
folderQuery := &m.GetDashboardsQuery{DashboardIds: dashboardFolderIds}
err := GetDashboards(folderQuery)
if err != nil {
return nil, err
}
for _, folder := range folderQuery.Result {
res = append(res, DashboardSearchProjection{ res = append(res, DashboardSearchProjection{
Id: folder.Id, Id: item.ParentId,
IsFolder: true, IsFolder: true,
Slug: folder.Slug, Slug: item.FolderSlug,
Title: folder.Title, Title: item.FolderTitle,
}) })
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment