1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-28 06:42:00 +03:00

refactor: remove handlerWrapper and use separate maps in registry

- Remove unnecessary handlerWrapper complexity from push notifications
- Use separate maps for handlers and protection status in registry
- Store handlers directly without indirection layer
- Maintain same instance identity for registered/retrieved handlers
- Preserve all protected handler functionality with cleaner implementation

Changes:
- internal/pushnotif/registry.go: Use separate handlers and protected maps
- push_notifications.go: Remove handlerWrapper, store handlers directly
- Maintain thread-safe operations with simplified code structure

Benefits:
- Reduced memory overhead (no wrapper objects)
- Direct handler storage without type conversion
- Cleaner, more maintainable code
- Same functionality with better performance
- Eliminated unnecessary complexity layer
- Preserved all existing behavior and safety guarantees
This commit is contained in:
Nedyalko Dyakov
2025-06-27 16:38:31 +03:00
parent ada72cefcd
commit 91805bc506
3 changed files with 18 additions and 34 deletions

View File

@ -35,7 +35,7 @@ func NewPushNotificationRegistry() *PushNotificationRegistry {
// RegisterHandler registers a handler for a specific push notification name.
func (r *PushNotificationRegistry) RegisterHandler(pushNotificationName string, handler PushNotificationHandler, protected bool) error {
return r.registry.RegisterHandler(pushNotificationName, &handlerWrapper{handler}, protected)
return r.registry.RegisterHandler(pushNotificationName, handler, protected)
}
// UnregisterHandler removes a handler for a specific push notification name.
@ -49,10 +49,8 @@ func (r *PushNotificationRegistry) GetHandler(pushNotificationName string) PushN
if handler == nil {
return nil
}
if wrapper, ok := handler.(*handlerWrapper); ok {
return wrapper.handler
}
return nil
// The handler is already a PushNotificationHandler since we store it directly
return handler.(PushNotificationHandler)
}
// GetRegisteredPushNotificationNames returns a list of all registered push notification names.
@ -83,15 +81,13 @@ func (p *PushNotificationProcessor) GetHandler(pushNotificationName string) Push
if handler == nil {
return nil
}
if wrapper, ok := handler.(*handlerWrapper); ok {
return wrapper.handler
}
return nil
// The handler is already a PushNotificationHandler since we store it directly
return handler.(PushNotificationHandler)
}
// RegisterHandler registers a handler for a specific push notification name.
func (p *PushNotificationProcessor) RegisterHandler(pushNotificationName string, handler PushNotificationHandler, protected bool) error {
return p.processor.RegisterHandler(pushNotificationName, &handlerWrapper{handler}, protected)
return p.processor.RegisterHandler(pushNotificationName, handler, protected)
}
// UnregisterHandler removes a handler for a specific push notification name.
@ -143,14 +139,7 @@ func (v *VoidPushNotificationProcessor) GetRegistryForTesting() *PushNotificatio
return nil
}
// handlerWrapper wraps the public PushNotificationHandler interface to implement the internal Handler interface.
type handlerWrapper struct {
handler PushNotificationHandler
}
func (w *handlerWrapper) HandlePushNotification(ctx context.Context, notification []interface{}) bool {
return w.handler.HandlePushNotification(ctx, notification)
}
// Redis Cluster push notification names
const (