Skip to content

Commit

Permalink
limit invoking go routines when only the model is AfterFindable (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sio4 authored and friesencr committed Sep 19, 2023
1 parent 1b7ec98 commit 900a32c
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,21 @@ func (m *Model) afterFind(c *Connection, eager bool) error {

wg := &errgroup.Group{}
for i := 0; i < rv.Len(); i++ {
func(i int) {
wg.Go(func() error {
y := rv.Index(i)
y = y.Addr()

if eager {
if x, ok := y.Interface().(AfterEagerFindable); ok {
return x.AfterEagerFind(c)
}
} else {
if x, ok := y.Interface().(AfterFindable); ok {
return x.AfterFind(c)
}
}

return nil
})
}(i)
elem := rv.Index(i).Addr()

if eager {
if x, ok := elem.Interface().(AfterEagerFindable); ok {
wg.Go(func() error {
return x.AfterEagerFind(c)
})
}
} else {
if x, ok := elem.Interface().(AfterFindable); ok {
wg.Go(func() error {
return x.AfterFind(c)
})
}
}
}

return wg.Wait()
Expand Down

0 comments on commit 900a32c

Please sign in to comment.