Folders: Reduce DB queries when counting and deleting resources under folders (#81153)
* Add folder store method for fetching all folder descendants * Modify GetDescendantCounts() to fetch folder descendants at once * Reduce DB calls when counting library panels under dashboard * Reduce DB calls when counting dashboards under folder * Reduce DB calls during folder delete * Modify folder registry to count/delete entities under multiple folders * Reduce DB calls when counting * Reduce DB calls when deleting
This commit is contained in:
@@ -64,7 +64,7 @@ func TestIntegrationCreate(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Cleanup(func() {
|
||||
err := folderStore.Delete(context.Background(), f.UID, orgID)
|
||||
err := folderStore.Delete(context.Background(), []string{f.UID}, orgID)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
@@ -102,7 +102,7 @@ func TestIntegrationCreate(t *testing.T) {
|
||||
assert.NotEmpty(t, parent.URL)
|
||||
|
||||
t.Cleanup(func() {
|
||||
err := folderStore.Delete(context.Background(), parent.UID, orgID)
|
||||
err := folderStore.Delete(context.Background(), []string{parent.UID}, orgID)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
assertAncestorUIDs(t, folderStore, parent, []string{folder.GeneralFolderUID})
|
||||
@@ -117,7 +117,7 @@ func TestIntegrationCreate(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
err := folderStore.Delete(context.Background(), f.UID, orgID)
|
||||
err := folderStore.Delete(context.Background(), []string{f.UID}, orgID)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
@@ -165,7 +165,7 @@ func TestIntegrationDelete(t *testing.T) {
|
||||
|
||||
t.Cleanup(func() {
|
||||
for _, uid := range ancestorUIDs[1:] {
|
||||
err := folderStore.Delete(context.Background(), uid, orgID)
|
||||
err := folderStore.Delete(context.Background(), []string{uid}, orgID)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
})
|
||||
@@ -178,7 +178,7 @@ func TestIntegrationDelete(t *testing.T) {
|
||||
*/
|
||||
|
||||
t.Run("deleting a leaf folder should succeed", func(t *testing.T) {
|
||||
err := folderStore.Delete(context.Background(), ancestorUIDs[len(ancestorUIDs)-1], orgID)
|
||||
err := folderStore.Delete(context.Background(), []string{ancestorUIDs[len(ancestorUIDs)-1]}, orgID)
|
||||
require.NoError(t, err)
|
||||
|
||||
children, err := folderStore.GetChildren(context.Background(), folder.GetChildrenQuery{
|
||||
@@ -221,7 +221,7 @@ func TestIntegrationUpdate(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, f.ParentUID, parent.UID)
|
||||
t.Cleanup(func() {
|
||||
err := folderStore.Delete(context.Background(), f.UID, orgID)
|
||||
err := folderStore.Delete(context.Background(), []string{f.UID}, orgID)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
@@ -393,7 +393,7 @@ func TestIntegrationGet(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Cleanup(func() {
|
||||
err := folderStore.Delete(context.Background(), f.UID, orgID)
|
||||
err := folderStore.Delete(context.Background(), []string{f.UID}, orgID)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
@@ -489,7 +489,7 @@ func TestIntegrationGetParents(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Cleanup(func() {
|
||||
err := folderStore.Delete(context.Background(), f.UID, orgID)
|
||||
err := folderStore.Delete(context.Background(), []string{f.UID}, orgID)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
@@ -561,7 +561,7 @@ func TestIntegrationGetChildren(t *testing.T) {
|
||||
|
||||
t.Cleanup(func() {
|
||||
for _, uid := range treeLeaves {
|
||||
err := folderStore.Delete(context.Background(), uid, orgID)
|
||||
err := folderStore.Delete(context.Background(), []string{uid}, orgID)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
})
|
||||
@@ -778,7 +778,7 @@ func TestIntegrationGetFolders(t *testing.T) {
|
||||
|
||||
t.Cleanup(func() {
|
||||
for _, uid := range uids {
|
||||
err := folderStore.Delete(context.Background(), uid, orgID)
|
||||
err := folderStore.Delete(context.Background(), []string{uid}, orgID)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user