mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 02:54:20 +00:00
fix: undo scan for current sequence in get by id (#1956)
* index on events for changes * check for current sequence before filter events * fix(migration): enable hash shared indexes feature * fix(database): drop changes idx as it slows unwanted queries * fix: remove check for current sequence after objects loaded as not all events are processed
This commit is contained in:
parent
d5626db71b
commit
992b598100
@ -34,13 +34,7 @@ func (repo *FeaturesRepo) GetDefaultFeatures(ctx context.Context) (*features_mod
|
||||
features = new(model.FeaturesView)
|
||||
}
|
||||
|
||||
sequence := features.Sequence
|
||||
currentSequence, err := repo.View.GetLatestFeaturesSequence()
|
||||
if err == nil {
|
||||
sequence = currentSequence.CurrentSequence
|
||||
}
|
||||
|
||||
events, esErr := repo.getIAMEvents(ctx, sequence)
|
||||
events, esErr := repo.getIAMEvents(ctx, features.Sequence)
|
||||
if errors.IsNotFound(viewErr) && len(events) == 0 {
|
||||
return nil, errors.ThrowNotFound(nil, "EVENT-Lsoj7", "Errors.Org.NotFound")
|
||||
}
|
||||
|
@ -139,13 +139,7 @@ func (repo *IAMRepository) GetDefaultLoginPolicy(ctx context.Context) (*iam_mode
|
||||
policy = new(iam_es_model.LoginPolicyView)
|
||||
}
|
||||
|
||||
sequence := policy.Sequence
|
||||
currentSequence, err := repo.View.GetLatestLoginPolicySequence()
|
||||
if err == nil {
|
||||
sequence = currentSequence.CurrentSequence
|
||||
}
|
||||
|
||||
events, esErr := repo.getIAMEvents(ctx, sequence)
|
||||
events, esErr := repo.getIAMEvents(ctx, policy.Sequence)
|
||||
if caos_errs.IsNotFound(viewErr) && len(events) == 0 {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "EVENT-cmO9s", "Errors.IAM.LoginPolicy.NotFound")
|
||||
}
|
||||
@ -218,13 +212,7 @@ func (repo *IAMRepository) GetDefaultPasswordComplexityPolicy(ctx context.Contex
|
||||
policy = new(iam_es_model.PasswordComplexityPolicyView)
|
||||
}
|
||||
|
||||
sequence := policy.Sequence
|
||||
currentSequence, err := repo.View.GetLatestPasswordComplexityPolicySequence()
|
||||
if err == nil {
|
||||
sequence = currentSequence.CurrentSequence
|
||||
}
|
||||
|
||||
events, esErr := repo.getIAMEvents(ctx, sequence)
|
||||
events, esErr := repo.getIAMEvents(ctx, policy.Sequence)
|
||||
if caos_errs.IsNotFound(viewErr) && len(events) == 0 {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "EVENT-1Mc0s", "Errors.IAM.PasswordComplexityPolicy.NotFound")
|
||||
}
|
||||
@ -250,13 +238,7 @@ func (repo *IAMRepository) GetDefaultPasswordAgePolicy(ctx context.Context) (*ia
|
||||
policy = new(iam_es_model.PasswordAgePolicyView)
|
||||
}
|
||||
|
||||
sequence := policy.Sequence
|
||||
currentSequence, err := repo.View.GetLatestPasswordAgePolicySequence()
|
||||
if err == nil {
|
||||
sequence = currentSequence.CurrentSequence
|
||||
}
|
||||
|
||||
events, esErr := repo.getIAMEvents(ctx, sequence)
|
||||
events, esErr := repo.getIAMEvents(ctx, policy.Sequence)
|
||||
if caos_errs.IsNotFound(viewErr) && len(events) == 0 {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "EVENT-vMyS3", "Errors.IAM.PasswordAgePolicy.NotFound")
|
||||
}
|
||||
@ -282,13 +264,7 @@ func (repo *IAMRepository) GetDefaultPasswordLockoutPolicy(ctx context.Context)
|
||||
policy = new(iam_es_model.PasswordLockoutPolicyView)
|
||||
}
|
||||
|
||||
sequence := policy.Sequence
|
||||
currentSequence, err := repo.View.GetLatestPasswordLockoutPolicySequence()
|
||||
if err == nil {
|
||||
sequence = currentSequence.CurrentSequence
|
||||
}
|
||||
|
||||
events, esErr := repo.getIAMEvents(ctx, sequence)
|
||||
events, esErr := repo.getIAMEvents(ctx, policy.Sequence)
|
||||
if caos_errs.IsNotFound(viewErr) && len(events) == 0 {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "EVENT-2M9oP", "Errors.IAM.PasswordLockoutPolicy.NotFound")
|
||||
}
|
||||
@ -314,13 +290,7 @@ func (repo *IAMRepository) GetOrgIAMPolicy(ctx context.Context) (*iam_model.OrgI
|
||||
policy = new(iam_es_model.OrgIAMPolicyView)
|
||||
}
|
||||
|
||||
sequence := policy.Sequence
|
||||
currentSequence, err := repo.View.GetLatestOrgIAMPolicySequence()
|
||||
if err == nil {
|
||||
sequence = currentSequence.CurrentSequence
|
||||
}
|
||||
|
||||
events, esErr := repo.getIAMEvents(ctx, sequence)
|
||||
events, esErr := repo.getIAMEvents(ctx, policy.Sequence)
|
||||
if caos_errs.IsNotFound(viewErr) && len(events) == 0 {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "EVENT-MkoL0", "Errors.IAM.OrgIAMPolicy.NotFound")
|
||||
}
|
||||
|
@ -38,13 +38,7 @@ func (repo *OrgRepo) OrgByID(ctx context.Context, id string) (*org_model.OrgView
|
||||
org = new(model.OrgView)
|
||||
}
|
||||
|
||||
sequence := org.Sequence
|
||||
currentSequence, err := repo.View.GetLatestOrgSequence()
|
||||
if err == nil {
|
||||
sequence = currentSequence.CurrentSequence
|
||||
}
|
||||
|
||||
events, esErr := repo.getOrgEvents(ctx, id, sequence)
|
||||
events, esErr := repo.getOrgEvents(ctx, id, org.Sequence)
|
||||
if errors.IsNotFound(viewErr) && len(events) == 0 {
|
||||
return nil, errors.ThrowNotFound(nil, "EVENT-Lsoj7", "Errors.Org.NotFound")
|
||||
}
|
||||
|
@ -41,13 +41,7 @@ func (r *RefreshTokenRepo) RefreshTokenByID(ctx context.Context, refreshToken st
|
||||
tokenView.UserID = userID
|
||||
}
|
||||
|
||||
sequence := tokenView.Sequence
|
||||
currentSequence, err := r.View.GetLatestRefreshTokenSequence()
|
||||
if err == nil {
|
||||
sequence = currentSequence.CurrentSequence
|
||||
}
|
||||
|
||||
events, esErr := r.getUserEvents(ctx, userID, sequence)
|
||||
events, esErr := r.getUserEvents(ctx, userID, tokenView.Sequence)
|
||||
if errors.IsNotFound(viewErr) && len(events) == 0 {
|
||||
return nil, errors.ThrowNotFound(nil, "EVENT-BHB52", "Errors.User.RefreshToken.Invalid")
|
||||
}
|
||||
|
@ -43,13 +43,7 @@ func (repo *TokenVerifierRepo) TokenByID(ctx context.Context, tokenID, userID st
|
||||
token.UserID = userID
|
||||
}
|
||||
|
||||
sequence := token.Sequence
|
||||
currentSequence, err := repo.View.GetLatestTokenSequence()
|
||||
if err == nil {
|
||||
sequence = currentSequence.CurrentSequence
|
||||
}
|
||||
|
||||
events, esErr := repo.getUserEvents(ctx, userID, sequence)
|
||||
events, esErr := repo.getUserEvents(ctx, userID, token.Sequence)
|
||||
if caos_errs.IsNotFound(viewErr) && len(events) == 0 {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "EVENT-4T90g", "Errors.Token.NotFound")
|
||||
}
|
||||
|
@ -42,13 +42,7 @@ func (repo *UserRepo) UserByID(ctx context.Context, id string) (*usr_model.UserV
|
||||
user = new(model.UserView)
|
||||
}
|
||||
|
||||
sequence := user.Sequence
|
||||
currentSequence, err := repo.View.GetLatestUserSequence()
|
||||
if err == nil {
|
||||
sequence = currentSequence.CurrentSequence
|
||||
}
|
||||
|
||||
events, esErr := repo.getUserEvents(ctx, id, sequence)
|
||||
events, esErr := repo.getUserEvents(ctx, id, user.Sequence)
|
||||
if caos_errs.IsNotFound(viewErr) && len(events) == 0 {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "EVENT-Lsoj7", "Errors.User.NotFound")
|
||||
}
|
||||
|
3
migrations/cockroach/V1.51__drop_changes_idx.sql
Normal file
3
migrations/cockroach/V1.51__drop_changes_idx.sql
Normal file
@ -0,0 +1,3 @@
|
||||
use eventstore;
|
||||
|
||||
drop index events@changes_idx;
|
Loading…
Reference in New Issue
Block a user