mirror of
https://github.com/grafana/grafana.git
synced 2025-07-29 04:22:39 +08:00
Zanzana: incorrect folder tree bug (#106478)
use pagination to get all folders
This commit is contained in:
@ -72,35 +72,48 @@ func folderTreeCollector(folderService folder.Service) legacyTupleCollector {
|
|||||||
|
|
||||||
ctx, ident := identity.WithServiceIdentity(ctx, orgID)
|
ctx, ident := identity.WithServiceIdentity(ctx, orgID)
|
||||||
|
|
||||||
q := folder.GetFoldersQuery{
|
|
||||||
OrgID: orgID,
|
|
||||||
SignedInUser: ident,
|
|
||||||
}
|
|
||||||
|
|
||||||
folders, err := folderService.GetFolders(ctx, q)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
tuples := make(map[string]map[string]*openfgav1.TupleKey)
|
tuples := make(map[string]map[string]*openfgav1.TupleKey)
|
||||||
|
|
||||||
for _, f := range folders {
|
const pageSize = 1000
|
||||||
var tuple *openfgav1.TupleKey
|
var page int64 = 1
|
||||||
if f.ParentUID == "" {
|
|
||||||
continue
|
for {
|
||||||
|
q := folder.GetFoldersQuery{
|
||||||
|
OrgID: orgID,
|
||||||
|
SignedInUser: ident,
|
||||||
|
Limit: pageSize,
|
||||||
|
Page: page,
|
||||||
}
|
}
|
||||||
|
|
||||||
tuple = &openfgav1.TupleKey{
|
folders, err := folderService.GetFolders(ctx, q)
|
||||||
Object: zanzana.NewTupleEntry(zanzana.TypeFolder, f.UID, ""),
|
if err != nil {
|
||||||
Relation: zanzana.RelationParent,
|
return nil, err
|
||||||
User: zanzana.NewTupleEntry(zanzana.TypeFolder, f.ParentUID, ""),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if tuples[tuple.Object] == nil {
|
for _, f := range folders {
|
||||||
tuples[tuple.Object] = make(map[string]*openfgav1.TupleKey)
|
var tuple *openfgav1.TupleKey
|
||||||
|
if f.ParentUID == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
tuple = &openfgav1.TupleKey{
|
||||||
|
Object: zanzana.NewTupleEntry(zanzana.TypeFolder, f.UID, ""),
|
||||||
|
Relation: zanzana.RelationParent,
|
||||||
|
User: zanzana.NewTupleEntry(zanzana.TypeFolder, f.ParentUID, ""),
|
||||||
|
}
|
||||||
|
|
||||||
|
if tuples[tuple.Object] == nil {
|
||||||
|
tuples[tuple.Object] = make(map[string]*openfgav1.TupleKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
tuples[tuple.Object][tuple.String()] = tuple
|
||||||
}
|
}
|
||||||
|
|
||||||
tuples[tuple.Object][tuple.String()] = tuple
|
if int64(len(folders)) < pageSize {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
page++
|
||||||
}
|
}
|
||||||
|
|
||||||
return tuples, nil
|
return tuples, nil
|
||||||
|
Reference in New Issue
Block a user