mirror of
https://github.com/binwiederhier/ntfy.git
synced 2024-06-28 02:51:15 +12:00
keep track of topics that have never been subscribed to
This commit is contained in:
parent
072520eacc
commit
8f5213ab1a
|
@ -19,11 +19,12 @@ const (
|
||||||
// topic represents a channel to which subscribers can subscribe, and publishers
|
// topic represents a channel to which subscribers can subscribe, and publishers
|
||||||
// can publish a message
|
// can publish a message
|
||||||
type topic struct {
|
type topic struct {
|
||||||
ID string
|
ID string
|
||||||
subscribers map[int]*topicSubscriber
|
subscribers map[int]*topicSubscriber
|
||||||
rateVisitor *visitor
|
rateVisitor *visitor
|
||||||
lastAccess time.Time
|
lastAccess time.Time
|
||||||
mu sync.RWMutex
|
neverSubscribed bool
|
||||||
|
mu sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
type topicSubscriber struct {
|
type topicSubscriber struct {
|
||||||
|
@ -41,6 +42,7 @@ func newTopic(id string) *topic {
|
||||||
ID: id,
|
ID: id,
|
||||||
subscribers: make(map[int]*topicSubscriber),
|
subscribers: make(map[int]*topicSubscriber),
|
||||||
lastAccess: time.Now(),
|
lastAccess: time.Now(),
|
||||||
|
neverSubscribed: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +63,7 @@ func (t *topic) Subscribe(s subscriber, userID string, cancel func()) (subscribe
|
||||||
cancel: cancel,
|
cancel: cancel,
|
||||||
}
|
}
|
||||||
t.lastAccess = time.Now()
|
t.lastAccess = time.Now()
|
||||||
|
t.neverSubscribed = false
|
||||||
return subscriberID
|
return subscriberID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +82,12 @@ func (t *topic) LastAccess() time.Time {
|
||||||
return t.lastAccess
|
return t.lastAccess
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *topic) NeverSubscribed() bool {
|
||||||
|
t.mu.RLock()
|
||||||
|
defer t.mu.RUnlock()
|
||||||
|
return t.neverSubscribed
|
||||||
|
}
|
||||||
|
|
||||||
func (t *topic) SetRateVisitor(v *visitor) {
|
func (t *topic) SetRateVisitor(v *visitor) {
|
||||||
t.mu.Lock()
|
t.mu.Lock()
|
||||||
defer t.mu.Unlock()
|
defer t.mu.Unlock()
|
||||||
|
|
Loading…
Reference in a new issue