feat: api key profile channel tags compposite, close #1220#1240
Merged
looplj merged 1 commit intorelease/v0.9.xfrom Apr 2, 2026
Merged
feat: api key profile channel tags compposite, close #1220#1240looplj merged 1 commit intorelease/v0.9.xfrom
looplj merged 1 commit intorelease/v0.9.xfrom
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a channelTagsMatchMode setting for API key profiles, allowing users to choose between 'any' and 'all' tag matching for channel filtering. The changes include frontend UI components, GraphQL schema updates, and backend logic for tag matching. Feedback suggests optimizing the MatchChannelTags method in internal/objects/apikey.go by using a map for lookups to improve time complexity from O(N*M) to O(N+M).
Comment on lines
+44
to
70
| func (p *APIKeyProfile) MatchChannelTags(tags []string) bool { | ||
| if p == nil || len(p.ChannelTags) == 0 { | ||
| return true | ||
| } | ||
|
|
||
| //nolint:exhaustive // Checked. | ||
| switch p.ChannelTagsMatchMode.OrDefault() { | ||
| case APIKeyMatchModeAll: | ||
| for _, allowedTag := range p.ChannelTags { | ||
| matched := slices.Contains(tags, allowedTag) | ||
|
|
||
| if !matched { | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| return true | ||
| default: | ||
| for _, tag := range tags { | ||
| if slices.Contains(p.ChannelTags, tag) { | ||
| return true | ||
| } | ||
| } | ||
|
|
||
| return false | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
The current implementation of MatchChannelTags uses slices.Contains within loops, which has a time complexity of O(N*M) and can be inefficient if the tag lists are large. This can be optimized to O(N+M) by using a map for lookups.
func (p *APIKeyProfile) MatchChannelTags(tags []string) bool {
if p == nil || len(p.ChannelTags) == 0 {
return true
}
//nolint:exhaustive // Checked.
switch p.ChannelTagsMatchMode.OrDefault() {
case APIKeyMatchModeAll:
// For 'all' mode, all of p.ChannelTags must be in tags.
// Create a set of the channel's tags for efficient lookup.
tagSet := make(map[string]struct{}, len(tags))
for _, tag := range tags {
tagSet[tag] = struct{}{}
}
for _, allowedTag := range p.ChannelTags {
if _, ok := tagSet[allowedTag]; !ok {
return false
}
}
return true
default: // APIKeyMatchModeAny
// For 'any' mode, at least one of the channel's tags must be in p.ChannelTags.
// It's generally more efficient to build a set from the allowed tags.
allowedTagSet := make(map[string]struct{}, len(p.ChannelTags))
for _, allowedTag := range p.ChannelTags {
allowedTagSet[allowedTag] = struct{}{}
}
for _, tag := range tags {
if _, ok := allowedTagSet[tag]; ok {
return true
}
}
return false
}
}
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.
Uh oh!
There was an error while loading. Please reload this page.