fix: delete folders using postorder (#113493)

* fix: delete folders using postorder

* chore: use helper function and do not add method to Folder store

- addresses other review comments fixing log messages and cleans up the unit tests

* chore: run library element tests on modes 2,3,5 only

* chore: adjust to folder.SortByPostorder(folders []*Folder)

* chore: run library panels tests in mode 2,3,5 only

* chore: run tests in all modes and increase timeout

- adjusting the modes and tweaking configs will be done separately
This commit is contained in:
Rafael Bortolon Paulovic
2025-11-06 15:04:34 +01:00
committed by GitHub
parent fbf1cdd0ce
commit e69f3c55f7
8 changed files with 314 additions and 8 deletions
+3 -2
View File
@@ -1241,15 +1241,16 @@ func (s *Service) nestedFolderDelete(ctx context.Context, cmd *folder.DeleteFold
s.log.ErrorContext(ctx, "failed to get descendant folders", "error", err)
return descendantUIDs, err
}
descendants = folder.SortByPostorder(descendants)
for _, f := range descendants {
descendantUIDs = append(descendantUIDs, f.UID)
}
s.log.InfoContext(ctx, "deleting folder descendants", "org_id", cmd.OrgID, "uid", cmd.UID)
s.log.InfoContext(ctx, "deleting legacy folder descendants", "org_id", cmd.OrgID, "uid", cmd.UID, "descendantsUIDs", strings.Join(descendantUIDs, ","))
err = s.store.Delete(ctx, descendantUIDs, cmd.OrgID)
if err != nil {
s.log.InfoContext(ctx, "failed deleting descendants", "org_id", cmd.OrgID, "parent_uid", cmd.UID, "err", err)
s.log.ErrorContext(ctx, "failed to delete legacy folder descendants", "org_id", cmd.OrgID, "parent_uid", cmd.UID, "descendantsUIDs", strings.Join(descendantUIDs, ","), "err", err)
return descendantUIDs, err
}
return descendantUIDs, nil
@@ -618,12 +618,14 @@ func (s *Service) deleteFromApiServer(ctx context.Context, cmd *folder.DeleteFol
if err != nil {
return err
}
descFolders = folder.SortByPostorder(descFolders)
folders := []string{}
for _, f := range descFolders {
folders = append(folders, f.UID)
}
// must delete children first, then the parent folder
s.log.InfoContext(ctx, "deleting folder with descendants", "org_id", cmd.OrgID, "uid", cmd.UID, "folderUIDs", strings.Join(folders, ","))
folders = append(folders, cmd.UID)
if cmd.ForceDeleteRules {
@@ -880,6 +880,7 @@ func TestIntegrationDeleteFoldersFromApiServer(t *testing.T) {
registry: make(map[string]folder.RegistryService),
features: featuremgmt.WithFeatures(),
tracer: tracer,
log: slog.New(logtest.NewNopHandler(t)),
}
user := &user.SignedInUser{OrgID: 1}
ctx := identity.WithRequester(context.Background(), user)