mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 13:52:15 +08:00
Folders: Use folder service to count library panels (#98802)
* Use folder service to count library panels --------- Co-authored-by: suntala <arati.rana@grafana.com>
This commit is contained in:
@ -195,19 +195,16 @@ func (lps LibraryPanelService) CountInFolders(ctx context.Context, orgID int64,
|
||||
if len(folderUIDs) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
var count int64
|
||||
return count, lps.SQLStore.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryPanels).Inc()
|
||||
// the sequential IDs for the respective entries of dashboard and folder tables are different,
|
||||
// so we need to get the folder ID from the dashboard table
|
||||
// TODO: In the future, we should consider adding a folder UID column to the library_element table
|
||||
// and use that instead of the folder ID.
|
||||
s := fmt.Sprintf(`SELECT COUNT(*) FROM library_element
|
||||
WHERE org_id = ? AND folder_id IN (SELECT id FROM dashboard WHERE org_id = ? AND uid IN (%s)) AND kind = ?`, strings.Repeat("?,", len(folderUIDs)-1)+"?")
|
||||
s := fmt.Sprintf(`SELECT COUNT(*) FROM library_element WHERE org_id = ? AND folder_uid IN (%s) AND kind = ?`, strings.Repeat("?,", len(folderUIDs)-1)+"?")
|
||||
|
||||
args := make([]interface{}, 0, len(folderUIDs)+2)
|
||||
args = append(args, orgID, orgID)
|
||||
for _, folderUID := range folderUIDs {
|
||||
args = append(args, folderUID)
|
||||
args = append(args, orgID)
|
||||
for _, uid := range folderUIDs {
|
||||
args = append(args, uid)
|
||||
}
|
||||
args = append(args, int64(model.PanelElement))
|
||||
_, err := sess.SQL(s, args...).Get(&count)
|
||||
|
@ -732,7 +732,7 @@ func createDashboard(t *testing.T, sqlStore db.DB, user *user.SignedInUser, dash
|
||||
dashPermissionService.On("SetPermissions", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]accesscontrol.ResourcePermission{}, nil)
|
||||
service, err := dashboardservice.ProvideDashboardServiceImpl(
|
||||
cfg, dashboardStore, folderStore,
|
||||
featuremgmt.WithFeatures(), acmock.NewMockedPermissionsService(), dashPermissionService, ac,
|
||||
features, acmock.NewMockedPermissionsService(), dashPermissionService, ac,
|
||||
foldertest.NewFakeService(), folder.NewFakeStore(),
|
||||
nil, nil, nil, nil, quotaService, nil,
|
||||
)
|
||||
|
Reference in New Issue
Block a user