Skip to content

Commit

Permalink
update query to ensure index is hit for certifyLegal, occurence and h…
Browse files Browse the repository at this point in the history
…asSBOM (guacsec#2201)

Signed-off-by: pxp928 <[email protected]>
  • Loading branch information
pxp928 authored Oct 16, 2024
1 parent cff089f commit ac93fb2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/assembler/backends/ent/backend/certifyLegal.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,15 @@ func certifyLegalQuery(filter model.CertifyLegalSpec) predicate.CertifyLegal {
if filter.Subject.Package != nil {
if filter.Subject.Package.ID != nil {
predicates = append(predicates, optionalPredicate(filter.Subject.Package.ID, packageIDEQ))
predicates = append(predicates, certifylegal.SourceIDIsNil())
} else {
predicates = append(predicates,
certifylegal.HasPackageWith(packageVersionQuery(filter.Subject.Package)))
}
} else if filter.Subject.Source != nil {
if filter.Subject.Source.ID != nil {
predicates = append(predicates, optionalPredicate(filter.Subject.Source.ID, sourceIDEQ))
predicates = append(predicates, certifylegal.PackageIDIsNil())
} else {
predicates = append(predicates,
certifylegal.HasSourceWith(sourceQuery(filter.Subject.Source)),
Expand Down
2 changes: 2 additions & 0 deletions pkg/assembler/backends/ent/backend/occurrence.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,15 @@ func isOccurrenceQuery(filter *model.IsOccurrenceSpec) predicate.Occurrence {
if filter.Subject.Package != nil {
if filter.Subject.Package.ID != nil {
predicates = append(predicates, optionalPredicate(filter.Subject.Package.ID, packageIDEQ))
predicates = append(predicates, occurrence.SourceIDIsNil())
} else {
predicates = append(predicates,
occurrence.HasPackageWith(packageVersionQuery(filter.Subject.Package)))
}
} else if filter.Subject.Source != nil {
if filter.Subject.Source.ID != nil {
predicates = append(predicates, optionalPredicate(filter.Subject.Source.ID, sourceIDEQ))
predicates = append(predicates, occurrence.PackageIDIsNil())
} else {
predicates = append(predicates,
occurrence.HasSourceWith(
Expand Down
2 changes: 2 additions & 0 deletions pkg/assembler/backends/ent/backend/sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ func hasSBOMQuery(spec model.HasSBOMSpec) predicate.BillOfMaterials {
if spec.Subject.Package != nil {
if spec.Subject.Package.ID != nil {
predicates = append(predicates, optionalPredicate(spec.Subject.Package.ID, packageIDEQ))
predicates = append(predicates, billofmaterials.ArtifactIDIsNil())
} else {
predicates = append(predicates,
billofmaterials.HasPackageWith(packageVersionQuery(spec.Subject.Package)))
Expand All @@ -352,6 +353,7 @@ func hasSBOMQuery(spec model.HasSBOMSpec) predicate.BillOfMaterials {
if spec.Subject.Artifact.ID != nil {
predicates = append(predicates,
optionalPredicate(spec.Subject.Artifact.ID, artifactIDEQ))
predicates = append(predicates, billofmaterials.PackageIDIsNil())
} else {
predicates = append(predicates,
billofmaterials.HasArtifactWith(artifactQueryPredicates(spec.Subject.Artifact)))
Expand Down

0 comments on commit ac93fb2

Please sign in to comment.