unified-storage: Reduce calls to the user service (#102934)

* Create ListByIdOrUID in user service

* create UnstructuredToLegacyFolderList 

* update GetFolders to use list parser

* update GetDescendants to use list parser

* update UnstructuredToLegacyFolder to also make a single call to the user service

---------

Co-authored-by: Stephanie Hingtgen <stephanie.hingtgen@grafana.com>
This commit is contained in:
Will Assis
2025-03-27 22:01:07 +02:00
committed by GitHub
co-authored by Stephanie Hingtgen
parent 7e3efb3df2
commit 51825cfffe
13 changed files with 643 additions and 63 deletions
+20
View File
@@ -25,6 +25,7 @@ type store interface {
Insert(context.Context, *user.User) (int64, error)
GetByID(context.Context, int64) (*user.User, error)
GetByUID(ctx context.Context, uid string) (*user.User, error)
ListByIdOrUID(ctx context.Context, uids []string, ids []int64) ([]*user.User, error)
GetByLogin(context.Context, *user.GetUserByLoginQuery) (*user.User, error)
GetByEmail(context.Context, *user.GetUserByEmailQuery) (*user.User, error)
Delete(context.Context, int64) error
@@ -127,6 +128,25 @@ func (ss *sqlStore) GetByUID(ctx context.Context, uid string) (*user.User, error
return &usr, err
}
func (ss *sqlStore) ListByIdOrUID(ctx context.Context, uids []string, ids []int64) ([]*user.User, error) {
users := make([]*user.User, 0)
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
err := sess.Table("user").In("uid", uids).OrIn("id", ids).Find(&users)
if err != nil {
return err
}
return nil
})
if err != nil {
return nil, err
}
return users, err
}
func (ss *sqlStore) notServiceAccountFilter() string {
return fmt.Sprintf("%s.is_service_account = %s",
ss.dialect.Quote("user"),