interal/api: replace liner array scan with hashmap lookup in domain validation

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Iac969e7dc6e4ca3f93410fccac1995636a6a6964
This commit is contained in:
raf 2026-03-01 20:08:50 +03:00
commit 4e0b8f0d0a
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
3 changed files with 77 additions and 9 deletions

View file

@ -230,3 +230,37 @@ func TestValidateEvent(t *testing.T) {
})
}
}
func BenchmarkValidate_SliceLookup(b *testing.B) {
// Simulate multi-site with 50 domains
domains := make([]string, 50)
for i := range 50 {
domains[i] = strings.Repeat("site", i) + ".com"
}
event := Event{
Domain: domains[49], // Worst case - last in list
Path: "/test",
}
for b.Loop() {
_ = event.Validate(domains)
}
}
func BenchmarkValidate_MapLookup(b *testing.B) {
// Simulate multi-site with 50 domains
domainMap := make(map[string]bool, 50)
for i := range 50 {
domainMap[strings.Repeat("site", i)+".com"] = true
}
event := Event{
Domain: strings.Repeat("site", 49) + ".com", // any position
Path: "/test",
}
for b.Loop() {
_ = event.ValidateWithMap(domainMap)
}
}