mirror of
https://github.com/grafana/grafana.git
synced 2025-08-06 01:00:24 +08:00
Nested Folders: Fix /api/folders pagination (#79447)
* Nested Folders: Fix /api/folders pagination We used to check access to the root folders after fetching them from the DB with pagination. This fix splits logic for fetching folders in: - fetching subfolders - fetching root folders and refactors the query for the latter so that is filters by folders with permissions * Add tests * Update benchmarks
This commit is contained in:

committed by
GitHub

parent
cf8e8852c3
commit
d89a8a3a82
@ -2,6 +2,7 @@ package folderimpl
|
||||
|
||||
import (
|
||||
"context"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -213,7 +214,7 @@ func (ss *sqlStore) GetParents(ctx context.Context, q folder.GetParentsQuery) ([
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := concurrency.ForEachJob(ctx, len(folders), len(folders), func(ctx context.Context, idx int) error {
|
||||
if err := concurrency.ForEachJob(ctx, len(folders), runtime.NumCPU(), func(ctx context.Context, idx int) error {
|
||||
folders[idx].WithURL()
|
||||
return nil
|
||||
}); err != nil {
|
||||
@ -240,13 +241,25 @@ func (ss *sqlStore) GetChildren(ctx context.Context, q folder.GetChildrenQuery)
|
||||
sql := strings.Builder{}
|
||||
args := make([]any, 0, 2)
|
||||
if q.UID == "" {
|
||||
sql.WriteString("SELECT * FROM folder WHERE parent_uid IS NULL AND org_id=? ORDER BY title ASC")
|
||||
sql.WriteString("SELECT * FROM folder WHERE parent_uid IS NULL AND org_id=?")
|
||||
args = append(args, q.OrgID)
|
||||
} else {
|
||||
sql.WriteString("SELECT * FROM folder WHERE parent_uid=? AND org_id=? ORDER BY title ASC")
|
||||
sql.WriteString("SELECT * FROM folder WHERE parent_uid=? AND org_id=?")
|
||||
args = append(args, q.UID, q.OrgID)
|
||||
}
|
||||
|
||||
if q.FolderUIDs != nil {
|
||||
sql.WriteString(" AND uid IN (?")
|
||||
for range q.FolderUIDs[1:] {
|
||||
sql.WriteString(", ?")
|
||||
}
|
||||
sql.WriteString(")")
|
||||
for _, uid := range q.FolderUIDs {
|
||||
args = append(args, uid)
|
||||
}
|
||||
}
|
||||
sql.WriteString(" ORDER BY title ASC")
|
||||
|
||||
if q.Limit != 0 {
|
||||
var offset int64 = 0
|
||||
if q.Page > 0 {
|
||||
@ -259,7 +272,7 @@ func (ss *sqlStore) GetChildren(ctx context.Context, q folder.GetChildrenQuery)
|
||||
return folder.ErrDatabaseError.Errorf("failed to get folder children: %w", err)
|
||||
}
|
||||
|
||||
if err := concurrency.ForEachJob(ctx, len(folders), len(folders), func(ctx context.Context, idx int) error {
|
||||
if err := concurrency.ForEachJob(ctx, len(folders), runtime.NumCPU(), func(ctx context.Context, idx int) error {
|
||||
folders[idx].WithURL()
|
||||
return nil
|
||||
}); err != nil {
|
||||
|
Reference in New Issue
Block a user