fix: avoid o(2n) complexity in acl lookup

This commit is contained in:
Stavros
2026-05-18 11:50:38 +03:00
parent f841095b27
commit 5d2ca65ea4
2 changed files with 14 additions and 18 deletions
+9 -7
View File
@@ -85,21 +85,23 @@ func (docker *DockerService) GetLabels(appDomain string) (*model.App, error) {
return nil, err
}
// fist pass - try to find an exact match for the domain
for _, appLabels := range labels.Apps {
var nameMatch *model.App
// First try to find a matching app by domain, then fallback to matching by app name (subdomain)
for appName, appLabels := range labels.Apps {
if appLabels.Config.Domain == appDomain {
docker.log.App.Debug().Str("id", inspect.ID).Str("name", inspect.Name).Msg("Found matching container by domain")
return &appLabels, nil
}
}
// second pass - if we didn't find a match by domain, try to find a match by app name (subdomain)
for appName, appLabels := range labels.Apps {
if strings.SplitN(appDomain, ".", 2)[0] == appName {
docker.log.App.Debug().Str("id", inspect.ID).Str("name", inspect.Name).Msg("Found matching container by app name")
return &appLabels, nil
nameMatch = &appLabels
}
}
if nameMatch != nil {
return nameMatch, nil
}
}
docker.log.App.Debug().Str("domain", appDomain).Msg("No matching container found for domain")