Commit d89c1260 by Daniel Lee

WIP: refactor dash search and remove extra query

parent 5cf40cbd
......@@ -154,6 +154,8 @@ type DashboardSearchProjection struct {
Term string
IsFolder bool
ParentId int64
FolderSlug string
FolderTitle string
}
func findDashboards(query *search.FindPersistedDashboardsQuery) ([]DashboardSearchProjection, error) {
......@@ -167,9 +169,10 @@ func findDashboards(query *search.FindPersistedDashboardsQuery) ([]DashboardSear
dashboard_tag.term,
dashboard.is_folder,
dashboard.parent_id,
pd.title as folder_title
f.slug as folder_slug,
f.title as folder_title
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`)
if query.IsStarred {
......@@ -268,26 +271,13 @@ func SearchDashboards(query *search.FindPersistedDashboardsQuery) error {
// appends parent folders for any hits to the search result
func appendDashboardFolders(res []DashboardSearchProjection) ([]DashboardSearchProjection, error) {
var dashboardFolderIds []int64
for _, item := range res {
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{
Id: folder.Id,
Id: item.ParentId,
IsFolder: true,
Slug: folder.Slug,
Title: folder.Title,
Slug: item.FolderSlug,
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