mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-08 22:31:04 +00:00
lib/api, lib/model: Fixes around event request tracking (#6774)
This commit is contained in:
parent
80ada1bb6c
commit
4f06708330
@ -1217,7 +1217,6 @@ func (s *service) postDBIgnores(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *service) getIndexEvents(w http.ResponseWriter, r *http.Request) {
|
||||
s.fss.OnEventRequest()
|
||||
mask := s.getEventMask(r.URL.Query().Get("events"))
|
||||
sub := s.getEventSub(mask)
|
||||
s.getEvents(w, r, sub)
|
||||
@ -1229,6 +1228,10 @@ func (s *service) getDiskEvents(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *service) getEvents(w http.ResponseWriter, r *http.Request, eventSub events.BufferedSubscription) {
|
||||
if eventSub.Mask()&(events.FolderSummary|events.FolderCompletion) != 0 {
|
||||
s.fss.OnEventRequest()
|
||||
}
|
||||
|
||||
qs := r.URL.Query()
|
||||
sinceStr := qs.Get("since")
|
||||
limitStr := qs.Get("limit")
|
||||
|
@ -17,3 +17,5 @@ type mockedEventSub struct{}
|
||||
func (s *mockedEventSub) Since(id int, into []events.Event, timeout time.Duration) []events.Event {
|
||||
select {}
|
||||
}
|
||||
|
||||
func (s *mockedEventSub) Mask() events.EventType { return 0 }
|
||||
|
@ -238,6 +238,7 @@ type Event struct {
|
||||
type Subscription interface {
|
||||
C() <-chan Event
|
||||
Poll(timeout time.Duration) (Event, error)
|
||||
Mask() EventType
|
||||
Unsubscribe()
|
||||
}
|
||||
|
||||
@ -432,6 +433,10 @@ func (s *subscription) C() <-chan Event {
|
||||
return s.events
|
||||
}
|
||||
|
||||
func (s *subscription) Mask() EventType {
|
||||
return s.mask
|
||||
}
|
||||
|
||||
func (s *subscription) Unsubscribe() {
|
||||
select {
|
||||
case s.toUnsubscribe <- s:
|
||||
@ -450,6 +455,7 @@ type bufferedSubscription struct {
|
||||
|
||||
type BufferedSubscription interface {
|
||||
Since(id int, into []Event, timeout time.Duration) []Event
|
||||
Mask() EventType
|
||||
}
|
||||
|
||||
func NewBufferedSubscription(s Subscription, size int) BufferedSubscription {
|
||||
@ -505,6 +511,10 @@ func (s *bufferedSubscription) Since(id int, into []Event, timeout time.Duration
|
||||
return into
|
||||
}
|
||||
|
||||
func (s *bufferedSubscription) Mask() EventType {
|
||||
return s.sub.Mask()
|
||||
}
|
||||
|
||||
// Error returns a string pointer suitable for JSON marshalling errors. It
|
||||
// retains the "null on success" semantics, but ensures the error result is a
|
||||
// string regardless of the underlying concrete error type.
|
||||
@ -540,4 +550,8 @@ func (*noopSubscription) Poll(timeout time.Duration) (Event, error) {
|
||||
return Event{}, errNoop
|
||||
}
|
||||
|
||||
func (s *noopSubscription) Mask() EventType {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (*noopSubscription) Unsubscribe() {}
|
||||
|
@ -22,7 +22,7 @@ import (
|
||||
"github.com/syncthing/syncthing/lib/util"
|
||||
)
|
||||
|
||||
const minSummaryInterval = time.Minute
|
||||
const maxDurationSinceLastEventReq = time.Minute
|
||||
|
||||
type FolderSummaryService interface {
|
||||
suture.Service
|
||||
@ -303,7 +303,7 @@ func (c *folderSummaryService) foldersToHandle() []string {
|
||||
c.lastEventReqMut.Lock()
|
||||
last := c.lastEventReq
|
||||
c.lastEventReqMut.Unlock()
|
||||
if time.Since(last) > minSummaryInterval {
|
||||
if time.Since(last) > maxDurationSinceLastEventReq {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user