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:
Silvan 2021-07-01 22:32:16 +02:00 committed by GitHub
parent d5626db71b
commit 992b598100
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 13 additions and 70 deletions

View File

@ -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")
}

View File

@ -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")
}

View File

@ -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")
}

View File

@ -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")
}

View File

@ -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")
}

View File

@ -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")
}

View File

@ -0,0 +1,3 @@
use eventstore;
drop index events@changes_idx;