fix(api): use the AND operator with the gin index when there's only one k-v pair set - #4436
Merged
Merged
Conversation
…only have one filter
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
grutt
approved these changes
Jul 15, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to improve performance for the workflow-run/task-run list endpoints when filtering by additional_metadata with a single k-v pair by forcing use of the GIN-backed containment path (and AND semantics, which are equivalent for a single pair).
Changes:
- Forces
UseGinIndexwhen exactly oneadditional_metadatafilter is provided. - Updates
additionalMetadataOperatorto take a filter count so the handler can forceANDwhen only one filter exists. - Minor refactor of option struct initialization formatting.
Comment on lines
145
to
+161
| @@ -156,6 +157,8 @@ func (t *V1WorkflowRunsService) WithDags(ctx context.Context, request gen.V1Work | |||
| opts.AdditionalMetadata = additionalMetadataFilters | |||
| } | |||
|
|
|||
| opts.AdditionalMetadataOperator = additionalMetadataOperator(request.Params.AdditionalMetadataOperator, numAdditionalMetaFilters) | |||
|
|
|||
Comment on lines
298
to
+314
| @@ -306,6 +310,8 @@ func (t *V1WorkflowRunsService) OnlyTasks(ctx context.Context, request gen.V1Wor | |||
| opts.AdditionalMetadata = additionalMetadataFilters | |||
| } | |||
|
|
|||
| opts.AdditionalMetadataOperator = additionalMetadataOperator(request.Params.AdditionalMetadataOperator, numAdditionalMetaFilters) | |||
|
|
|||
Comment on lines
391
to
+397
| // additionalMetadataOperator maps the optional additional_metadata_operator query | ||
| // param to the repository operator, defaulting to OR | ||
| func additionalMetadataOperator(param *gen.V1AdditionalMetadataOperator) v1.AdditionalMetadataOperator { | ||
| func additionalMetadataOperator(param *gen.V1AdditionalMetadataOperator, numFilters int) v1.AdditionalMetadataOperator { | ||
| // if we only have one filter, always use the `AND` since it's the most performant way, and both methods are equivalent | ||
| if numFilters <= 1 { | ||
| return v1.AdditionalMetadataOperatorAnd | ||
| } |
Contributor
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Improves the performance of the run list API(s) when only one k-v pair for the additional meta filter is provided by always using the
ANDquery in that case, since it'll use the index and is the fastest optionType of change
Checklist
Changes have been:
🤖 AI Disclosure
No AI use