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