Skip to content

Commit

Permalink
Optimize dns performance for non-glob use case
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Aresty authored and Difan Zhao committed Apr 12, 2018
1 parent 121ec34 commit f5a8d25
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/bosh-dns/dns/server/criteria/criteria.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ func Field(field string, values []string) Matcher {
}

func globMatches(field, value string) bool {
if !strings.Contains(value, "*") {
return field == value
} else if value == "*" {
if value == "*" {
return true
} else if strings.HasPrefix(value, "*") {
return strings.HasSuffix(field, value[1:])
Expand All @@ -121,11 +119,20 @@ func FieldMatcher(field, value string) MatcherFunc {
case "instanceName":
return func(r *record.Record) bool { return r.ID == value }
case "instanceGroupName":
return func(r *record.Record) bool { return globMatches(r.Group, value) }
if strings.Contains(value, "*") {
return func(r *record.Record) bool { return globMatches(r.Group, value) }
}
return func(r *record.Record) bool { return r.Group == value }
case "network":
return func(r *record.Record) bool { return globMatches(r.Network, value) }
if strings.Contains(value, "*") {
return func(r *record.Record) bool { return globMatches(r.Network, value) }
}
return func(r *record.Record) bool { return r.Network == value }
case "deployment":
return func(r *record.Record) bool { return globMatches(r.Deployment, value) }
if strings.Contains(value, "*") {
return func(r *record.Record) bool { return globMatches(r.Deployment, value) }
}
return func(r *record.Record) bool { return r.Deployment == value }
case "domain":
return func(r *record.Record) bool { return r.Domain == value }

Expand Down

0 comments on commit f5a8d25

Please sign in to comment.