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

refactor: remove unnecessary enabled field and IsEnabled/SetEnabled methods

- Remove enabled field from PushNotificationProcessor struct
- Remove IsEnabled() and SetEnabled() methods from processor interface
- Remove enabled parameter from NewPushNotificationProcessor()
- Update all interfaces in pool package to remove IsEnabled requirement
- Simplify processor logic - if processor exists, it works
- VoidPushNotificationProcessor handles disabled case by discarding notifications
- Update all tests to use simplified interface without enable/disable logic

Benefits:
- Simpler, cleaner interface with less complexity
- No unnecessary state management for enabled/disabled
- VoidPushNotificationProcessor pattern handles disabled case elegantly
- Reduced cognitive overhead - processors just work when set
- Eliminates redundant enabled checks throughout codebase
- More predictable behavior - set processor = it works
This commit is contained in:
Nedyalko Dyakov
2025-06-27 01:18:15 +03:00
parent fdfcf94300
commit be9b6dd6a0
7 changed files with 57 additions and 99 deletions

View File

@ -106,8 +106,6 @@ func (r *PushNotificationRegistry) HasHandlers() bool {
// PushNotificationProcessorInterface defines the interface for push notification processors.
type PushNotificationProcessorInterface interface {
IsEnabled() bool
SetEnabled(enabled bool)
GetRegistry() *PushNotificationRegistry
ProcessPendingNotifications(ctx context.Context, rd *proto.Reader) error
RegisterHandler(pushNotificationName string, handler PushNotificationHandler, protected bool) error
@ -116,32 +114,15 @@ type PushNotificationProcessorInterface interface {
// PushNotificationProcessor handles the processing of push notifications from Redis.
type PushNotificationProcessor struct {
registry *PushNotificationRegistry
enabled bool
mu sync.RWMutex // Protects enabled field
}
// NewPushNotificationProcessor creates a new push notification processor.
func NewPushNotificationProcessor(enabled bool) *PushNotificationProcessor {
func NewPushNotificationProcessor() *PushNotificationProcessor {
return &PushNotificationProcessor{
registry: NewPushNotificationRegistry(),
enabled: enabled,
}
}
// IsEnabled returns whether push notification processing is enabled.
func (p *PushNotificationProcessor) IsEnabled() bool {
p.mu.RLock()
defer p.mu.RUnlock()
return p.enabled
}
// SetEnabled enables or disables push notification processing.
func (p *PushNotificationProcessor) SetEnabled(enabled bool) {
p.mu.Lock()
defer p.mu.Unlock()
p.enabled = enabled
}
// GetRegistry returns the push notification registry.
func (p *PushNotificationProcessor) GetRegistry() *PushNotificationRegistry {
return p.registry
@ -149,7 +130,7 @@ func (p *PushNotificationProcessor) GetRegistry() *PushNotificationRegistry {
// ProcessPendingNotifications checks for and processes any pending push notifications.
func (p *PushNotificationProcessor) ProcessPendingNotifications(ctx context.Context, rd *proto.Reader) error {
if !p.IsEnabled() || !p.registry.HasHandlers() {
if !p.registry.HasHandlers() {
return nil
}
@ -252,16 +233,6 @@ func NewVoidPushNotificationProcessor() *VoidPushNotificationProcessor {
return &VoidPushNotificationProcessor{}
}
// IsEnabled always returns false for void processor.
func (v *VoidPushNotificationProcessor) IsEnabled() bool {
return false
}
// SetEnabled is a no-op for void processor.
func (v *VoidPushNotificationProcessor) SetEnabled(enabled bool) {
// No-op: void processor is always disabled
}
// GetRegistry returns nil for void processor since it doesn't maintain handlers.
func (v *VoidPushNotificationProcessor) GetRegistry() *PushNotificationRegistry {
return nil