diff --git a/lib/api/api.go b/lib/api/api.go index bcd1ca693..a8e5edba3 100644 --- a/lib/api/api.go +++ b/lib/api/api.go @@ -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") diff --git a/lib/api/mocked_events_test.go b/lib/api/mocked_events_test.go index 4bf079dca..149852537 100644 --- a/lib/api/mocked_events_test.go +++ b/lib/api/mocked_events_test.go @@ -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 } diff --git a/lib/events/events.go b/lib/events/events.go index 72ea6446f..687adb3ff 100644 --- a/lib/events/events.go +++ b/lib/events/events.go @@ -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() {} diff --git a/lib/model/folder_summary.go b/lib/model/folder_summary.go index eb11f6779..b87e8eb16 100644 --- a/lib/model/folder_summary.go +++ b/lib/model/folder_summary.go @@ -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 }