Skip to content

Commit ac93fb2

Browse files
authored
update query to ensure index is hit for certifyLegal, occurence and hasSBOM (#2201)
Signed-off-by: pxp928 <[email protected]>
1 parent cff089f commit ac93fb2

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

pkg/assembler/backends/ent/backend/certifyLegal.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,13 +404,15 @@ func certifyLegalQuery(filter model.CertifyLegalSpec) predicate.CertifyLegal {
404404
if filter.Subject.Package != nil {
405405
if filter.Subject.Package.ID != nil {
406406
predicates = append(predicates, optionalPredicate(filter.Subject.Package.ID, packageIDEQ))
407+
predicates = append(predicates, certifylegal.SourceIDIsNil())
407408
} else {
408409
predicates = append(predicates,
409410
certifylegal.HasPackageWith(packageVersionQuery(filter.Subject.Package)))
410411
}
411412
} else if filter.Subject.Source != nil {
412413
if filter.Subject.Source.ID != nil {
413414
predicates = append(predicates, optionalPredicate(filter.Subject.Source.ID, sourceIDEQ))
415+
predicates = append(predicates, certifylegal.PackageIDIsNil())
414416
} else {
415417
predicates = append(predicates,
416418
certifylegal.HasSourceWith(sourceQuery(filter.Subject.Source)),

pkg/assembler/backends/ent/backend/occurrence.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,15 @@ func isOccurrenceQuery(filter *model.IsOccurrenceSpec) predicate.Occurrence {
403403
if filter.Subject.Package != nil {
404404
if filter.Subject.Package.ID != nil {
405405
predicates = append(predicates, optionalPredicate(filter.Subject.Package.ID, packageIDEQ))
406+
predicates = append(predicates, occurrence.SourceIDIsNil())
406407
} else {
407408
predicates = append(predicates,
408409
occurrence.HasPackageWith(packageVersionQuery(filter.Subject.Package)))
409410
}
410411
} else if filter.Subject.Source != nil {
411412
if filter.Subject.Source.ID != nil {
412413
predicates = append(predicates, optionalPredicate(filter.Subject.Source.ID, sourceIDEQ))
414+
predicates = append(predicates, occurrence.PackageIDIsNil())
413415
} else {
414416
predicates = append(predicates,
415417
occurrence.HasSourceWith(

pkg/assembler/backends/ent/backend/sbom.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ func hasSBOMQuery(spec model.HasSBOMSpec) predicate.BillOfMaterials {
344344
if spec.Subject.Package != nil {
345345
if spec.Subject.Package.ID != nil {
346346
predicates = append(predicates, optionalPredicate(spec.Subject.Package.ID, packageIDEQ))
347+
predicates = append(predicates, billofmaterials.ArtifactIDIsNil())
347348
} else {
348349
predicates = append(predicates,
349350
billofmaterials.HasPackageWith(packageVersionQuery(spec.Subject.Package)))
@@ -352,6 +353,7 @@ func hasSBOMQuery(spec model.HasSBOMSpec) predicate.BillOfMaterials {
352353
if spec.Subject.Artifact.ID != nil {
353354
predicates = append(predicates,
354355
optionalPredicate(spec.Subject.Artifact.ID, artifactIDEQ))
356+
predicates = append(predicates, billofmaterials.PackageIDIsNil())
355357
} else {
356358
predicates = append(predicates,
357359
billofmaterials.HasArtifactWith(artifactQueryPredicates(spec.Subject.Artifact)))

0 commit comments

Comments
 (0)