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