Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

Commit

Permalink
Refactor MetricEvent out of loop
Browse files Browse the repository at this point in the history
We're now only creating a single MetricEvent for all handlers.
  • Loading branch information
ankur22 committed Oct 7, 2024
1 parent d39873d commit ca5be65
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions common/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,29 +383,28 @@ func (p *Page) urlTagName(ctx context.Context, urlTag string) (string, bool) {

var name string
var nameChanged bool
em := &MetricEvent{
urlTag: urlTag,
}

for _, h := range p.eventHandlers[EventPageMetricCalled] {
// A handler can register another handler from within itself. This is
// the reason to unlock the mutex before calling the handler.
p.eventHandlersMu.RUnlock()

em := &MetricEvent{
urlTag: urlTag,
}

// Call and wait for the handler to complete.
h(em)

// If a match was found then the name field in em will have been updated.
if em.name != nil {
name = *em.name
nameChanged = true
}

p.eventHandlersMu.RLock()
}
p.eventHandlersMu.RUnlock()

// If a match was found then the name field in em will have been updated.
if em.name != nil {
name = *em.name
nameChanged = true
}

p.logger.Debugf("urlTagName", "name: %q nameChanged: %v", name, nameChanged)

return name, nameChanged
Expand Down

0 comments on commit ca5be65

Please sign in to comment.