lib/model: Incremental block stats usage reporting

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4498
LGTM: calmh
This commit is contained in:
Audrius Butkevicius
2017-11-09 21:16:29 +00:00
parent a9d422e008
commit 386cb274bd
6 changed files with 34 additions and 47 deletions

View File

@@ -104,7 +104,7 @@ type modelIntf interface {
CurrentSequence(folder string) (int64, bool)
RemoteSequence(folder string) (int64, bool)
State(folder string) (string, time.Time, error)
UsageReportingStats(version int) map[string]interface{}
UsageReportingStats(version int, preview bool) map[string]interface{}
}
type configIntf interface {
@@ -980,7 +980,7 @@ func (s *apiService) getReport(w http.ResponseWriter, r *http.Request) {
if val, _ := strconv.Atoi(r.URL.Query().Get("version")); val > 0 {
version = val
}
sendJSON(w, reportData(s.cfg, s.model, s.connectionsService, version))
sendJSON(w, reportData(s.cfg, s.model, s.connectionsService, version, true))
}
func (s *apiService) getRandomString(w http.ResponseWriter, r *http.Request) {

View File

@@ -115,6 +115,6 @@ func (m *mockedModel) State(folder string) (string, time.Time, error) {
return "", time.Time{}, nil
}
func (m *mockedModel) UsageReportingStats(version int) map[string]interface{} {
func (m *mockedModel) UsageReportingStats(version int, preview bool) map[string]interface{} {
return nil
}

View File

@@ -36,7 +36,7 @@ const usageReportVersion = 3
// reportData returns the data to be sent in a usage report. It's used in
// various places, so not part of the usageReportingManager object.
func reportData(cfg configIntf, m modelIntf, connectionsService connectionsIntf, version int) map[string]interface{} {
func reportData(cfg configIntf, m modelIntf, connectionsService connectionsIntf, version int, preview bool) map[string]interface{} {
opts := cfg.Options()
res := make(map[string]interface{})
res["urVersion"] = version
@@ -310,7 +310,7 @@ func reportData(cfg configIntf, m modelIntf, connectionsService connectionsIntf,
res["guiStats"] = guiStatsInterface
}
for key, value := range m.UsageReportingStats(version) {
for key, value := range m.UsageReportingStats(version, preview) {
res[key] = value
}
@@ -338,7 +338,7 @@ func newUsageReportingService(cfg *config.Wrapper, model *model.Model, connectio
}
func (s *usageReportingService) sendUsageReport() error {
d := reportData(s.cfg, s.model, s.connectionsService, s.cfg.Options().URAccepted)
d := reportData(s.cfg, s.model, s.connectionsService, s.cfg.Options().URAccepted, false)
var b bytes.Buffer
json.NewEncoder(&b).Encode(d)