From c94a9d40234c9f949fa38dd0bab2b6b0a40f34a6 Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Fri, 6 Feb 2026 10:45:07 +0000 Subject: [PATCH] appview/notify: remove reflection usage in mergedNotifier Signed-off-by: oppiliappan --- appview/notify/merged_notifier.go | 51 ++++++++++++------------------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/appview/notify/merged_notifier.go b/appview/notify/merged_notifier.go index fbdb1646..a17c5077 100644 --- a/appview/notify/merged_notifier.go +++ b/appview/notify/merged_notifier.go @@ -2,105 +2,94 @@ package notify import ( "context" - "log/slog" - "reflect" "sync" "github.com/bluesky-social/indigo/atproto/syntax" "tangled.org/core/appview/models" - "tangled.org/core/log" ) type mergedNotifier struct { notifiers []Notifier - logger *slog.Logger } -func NewMergedNotifier(notifiers []Notifier, logger *slog.Logger) Notifier { - return &mergedNotifier{notifiers, logger} +func NewMergedNotifier(notifiers []Notifier) Notifier { + return &mergedNotifier{notifiers} } var _ Notifier = &mergedNotifier{} // fanout calls the same method on all notifiers concurrently -func (m *mergedNotifier) fanout(method string, ctx context.Context, args ...any) { - ctx = log.IntoContext(ctx, m.logger.With("method", method)) +func (m *mergedNotifier) fanout(callback func(Notifier)) { var wg sync.WaitGroup for _, n := range m.notifiers { wg.Add(1) go func(notifier Notifier) { defer wg.Done() - v := reflect.ValueOf(notifier).MethodByName(method) - in := make([]reflect.Value, len(args)+1) - in[0] = reflect.ValueOf(ctx) - for i, arg := range args { - in[i+1] = reflect.ValueOf(arg) - } - v.Call(in) + callback(n) }(n) } } func (m *mergedNotifier) NewRepo(ctx context.Context, repo *models.Repo) { - m.fanout("NewRepo", ctx, repo) + m.fanout(func(n Notifier) { n.NewRepo(ctx, repo) }) } func (m *mergedNotifier) NewStar(ctx context.Context, star *models.Star) { - m.fanout("NewStar", ctx, star) + m.fanout(func(n Notifier) { n.NewStar(ctx, star) }) } func (m *mergedNotifier) DeleteStar(ctx context.Context, star *models.Star) { - m.fanout("DeleteStar", ctx, star) + m.fanout(func(n Notifier) { n.DeleteStar(ctx, star) }) } func (m *mergedNotifier) NewIssue(ctx context.Context, issue *models.Issue, mentions []syntax.DID) { - m.fanout("NewIssue", ctx, issue, mentions) + m.fanout(func(n Notifier) { n.NewIssue(ctx, issue, mentions) }) } func (m *mergedNotifier) NewIssueComment(ctx context.Context, comment *models.IssueComment, mentions []syntax.DID) { - m.fanout("NewIssueComment", ctx, comment, mentions) + m.fanout(func(n Notifier) { n.NewIssueComment(ctx, comment, mentions) }) } func (m *mergedNotifier) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) { - m.fanout("NewIssueState", ctx, actor, issue) + m.fanout(func(n Notifier) { n.NewIssueState(ctx, actor, issue) }) } func (m *mergedNotifier) DeleteIssue(ctx context.Context, issue *models.Issue) { - m.fanout("DeleteIssue", ctx, issue) + m.fanout(func(n Notifier) { n.DeleteIssue(ctx, issue) }) } func (m *mergedNotifier) NewFollow(ctx context.Context, follow *models.Follow) { - m.fanout("NewFollow", ctx, follow) + m.fanout(func(n Notifier) { n.NewFollow(ctx, follow) }) } func (m *mergedNotifier) DeleteFollow(ctx context.Context, follow *models.Follow) { - m.fanout("DeleteFollow", ctx, follow) + m.fanout(func(n Notifier) { n.DeleteFollow(ctx, follow) }) } func (m *mergedNotifier) NewPull(ctx context.Context, pull *models.Pull) { - m.fanout("NewPull", ctx, pull) + m.fanout(func(n Notifier) { n.NewPull(ctx, pull) }) } func (m *mergedNotifier) NewPullComment(ctx context.Context, comment *models.PullComment, mentions []syntax.DID) { - m.fanout("NewPullComment", ctx, comment, mentions) + m.fanout(func(n Notifier) { n.NewPullComment(ctx, comment, mentions) }) } func (m *mergedNotifier) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) { - m.fanout("NewPullState", ctx, actor, pull) + m.fanout(func(n Notifier) { n.NewPullState(ctx, actor, pull) }) } func (m *mergedNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) { - m.fanout("UpdateProfile", ctx, profile) + m.fanout(func(n Notifier) { n.UpdateProfile(ctx, profile) }) } func (m *mergedNotifier) NewString(ctx context.Context, s *models.String) { - m.fanout("NewString", ctx, s) + m.fanout(func(n Notifier) { n.NewString(ctx, s) }) } func (m *mergedNotifier) EditString(ctx context.Context, s *models.String) { - m.fanout("EditString", ctx, s) + m.fanout(func(n Notifier) { n.EditString(ctx, s) }) } func (m *mergedNotifier) DeleteString(ctx context.Context, did, rkey string) { - m.fanout("DeleteString", ctx, did, rkey) + m.fanout(func(n Notifier) { n.DeleteString(ctx, did, rkey) }) } -- 2.51.2