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