Skip to content

Commit

Permalink
fix: util func to convert id or name of tenants to ids (#17950)
Browse files Browse the repository at this point in the history
Co-authored-by: Qiu Jian <[email protected]>
  • Loading branch information
swordqiu and Qiu Jian authored Sep 6, 2023
1 parent 147e872 commit f047629
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions pkg/cloudcommon/db/tenantcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,3 +552,29 @@ func (tenant *STenant) GetAllClassMetadata() (map[string]string, error) {
}
return ret, nil
}

func (manager *STenantCacheManager) ConvertIds(ids []string, isDomain bool) ([]string, error) {
var q *sqlchemy.SQuery
if isDomain {
q = manager.GetDomainQuery("id")
} else {
q = manager.GetTenantQuery("id")
}
q = q.Filter(sqlchemy.OR(
sqlchemy.In(q.Field("id"), ids),
sqlchemy.In(q.Field("name"), ids),
))
q = q.Distinct()
results := []struct {
Id string
}{}
err := q.All(&results)
if err != nil {
return nil, errors.Wrap(err, "query")
}
ret := make([]string, len(results))
for i := range results {
ret[i] = results[i].Id
}
return ret, nil
}

0 comments on commit f047629

Please sign in to comment.