mirror of
https://github.com/zitadel/zitadel.git
synced 2025-03-02 21:31:45 +00:00
fix(query): separate login policy queries (#7174)
This change moves IDPLoginPolicyLinks out of the scan function Login Policy queries in order to prevent potential deadlocks.
This commit is contained in:
parent
925eb2f2f9
commit
cba99da3b2
@ -198,29 +198,22 @@ func (q *Queries) LoginPolicyByID(ctx context.Context, shouldTriggerBulk bool, o
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = q.client.QueryContext(ctx, func(rows *sql.Rows) error {
|
err = q.client.QueryContext(ctx, func(rows *sql.Rows) error {
|
||||||
policy, err = q.scanAndAddLinksToLoginPolicy(ctx, rows, scan)
|
policy, err = scan(rows)
|
||||||
return err
|
return err
|
||||||
}, stmt, args...)
|
}, stmt, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, zerrors.ThrowInternal(err, "QUERY-SWgr3", "Errors.Internal")
|
return nil, zerrors.ThrowInternal(err, "QUERY-SWgr3", "Errors.Internal")
|
||||||
}
|
}
|
||||||
return policy, nil
|
return policy, q.addLinksToLoginPolicy(ctx, policy)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) scanAndAddLinksToLoginPolicy(ctx context.Context, rows *sql.Rows, scan func(*sql.Rows) (*LoginPolicy, error)) (*LoginPolicy, error) {
|
func (q *Queries) addLinksToLoginPolicy(ctx context.Context, policy *LoginPolicy) error {
|
||||||
policy, err := scan(rows)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
links, err := q.IDPLoginPolicyLinks(ctx, policy.OrgID, &IDPLoginPolicyLinksSearchQuery{}, false)
|
links, err := q.IDPLoginPolicyLinks(ctx, policy.OrgID, &IDPLoginPolicyLinksSearchQuery{}, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return zerrors.ThrowInternal(err, "QUERY-aa4Ve", "Errors.Internal")
|
||||||
}
|
}
|
||||||
for _, link := range links.Links {
|
policy.IDPLinks = append(policy.IDPLinks, links.Links...)
|
||||||
policy.IDPLinks = append(policy.IDPLinks, link)
|
return nil
|
||||||
}
|
|
||||||
return policy, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) DefaultLoginPolicy(ctx context.Context) (policy *LoginPolicy, err error) {
|
func (q *Queries) DefaultLoginPolicy(ctx context.Context) (policy *LoginPolicy, err error) {
|
||||||
@ -237,13 +230,13 @@ func (q *Queries) DefaultLoginPolicy(ctx context.Context) (policy *LoginPolicy,
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = q.client.QueryContext(ctx, func(rows *sql.Rows) error {
|
err = q.client.QueryContext(ctx, func(rows *sql.Rows) error {
|
||||||
policy, err = q.scanAndAddLinksToLoginPolicy(ctx, rows, scan)
|
policy, err = scan(rows)
|
||||||
return err
|
return err
|
||||||
}, stmt, args...)
|
}, stmt, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, zerrors.ThrowInternal(err, "QUERY-SArt2", "Errors.Internal")
|
return nil, zerrors.ThrowInternal(err, "QUERY-SArt2", "Errors.Internal")
|
||||||
}
|
}
|
||||||
return policy, nil
|
return policy, q.addLinksToLoginPolicy(ctx, policy)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) SecondFactorsByOrg(ctx context.Context, orgID string) (factors *SecondFactors, err error) {
|
func (q *Queries) SecondFactorsByOrg(ctx context.Context, orgID string) (factors *SecondFactors, err error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user