[nested folder]Add circular reference detection in create nested folder (#60163)

* add circulic reference detection in create neste folder

* redeclare mock

* add log for getHeight when depassing limit
This commit is contained in:
ying-jeanne
2022-12-15 00:07:55 +08:00
committed by GitHub
parent 7c3ab4a715
commit b059296cb0
3 changed files with 80 additions and 3 deletions
+4 -1
View File
@@ -268,7 +268,7 @@ func (ss *sqlStore) getParentsMySQL(ctx context.Context, cmd folder.GetParentsQu
func (ss *sqlStore) GetHeight(ctx context.Context, foldrUID string, orgID int64, parentUID *string) (int, error) {
height := -1
queue := []string{foldrUID}
for len(queue) > 0 {
for len(queue) > 0 && height <= folder.MaxNestedFolderDepth {
length := len(queue)
height++
for i := 0; i < length; i++ {
@@ -286,5 +286,8 @@ func (ss *sqlStore) GetHeight(ctx context.Context, foldrUID string, orgID int64,
}
}
}
if height > folder.MaxNestedFolderDepth {
ss.log.Warn("folder height exceeds the maximum allowed depth, You might have a circular reference", "uid", foldrUID, "orgId", orgID, "maxDepth", folder.MaxNestedFolderDepth)
}
return height, nil
}