From 388e4db9cdc569b9c1956050fa7d938cff34cb3e Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Thu, 28 Jul 2022 17:28:24 +0200 Subject: [PATCH] all: Combine sequential appends (#8461) --- cmd/ursrv/main.go | 113 ++++++++++++++------------------- lib/model/sentdownloadstate.go | 25 ++++---- 2 files changed, 60 insertions(+), 78 deletions(-) diff --git a/cmd/ursrv/main.go b/cmd/ursrv/main.go index 9f21c8502..830f8d45d 100644 --- a/cmd/ursrv/main.go +++ b/cmd/ursrv/main.go @@ -785,72 +785,53 @@ func getReport(db *sql.DB) map[string]interface{} { } } - var categories []category - categories = append(categories, category{ - Values: statsForInts(totFiles), - Descr: "Files Managed per Device", - }) - - categories = append(categories, category{ - Values: statsForInts(maxFiles), - Descr: "Files in Largest Folder", - }) - - categories = append(categories, category{ - Values: statsForInt64s(totMiB), - Descr: "Data Managed per Device", - Unit: "B", - Type: NumberBinary, - }) - - categories = append(categories, category{ - Values: statsForInt64s(maxMiB), - Descr: "Data in Largest Folder", - Unit: "B", - Type: NumberBinary, - }) - - categories = append(categories, category{ - Values: statsForInts(numDevices), - Descr: "Number of Devices in Cluster", - }) - - categories = append(categories, category{ - Values: statsForInts(numFolders), - Descr: "Number of Folders Configured", - }) - - categories = append(categories, category{ - Values: statsForInt64s(memoryUsage), - Descr: "Memory Usage", - Unit: "B", - Type: NumberBinary, - }) - - categories = append(categories, category{ - Values: statsForInt64s(memorySize), - Descr: "System Memory", - Unit: "B", - Type: NumberBinary, - }) - - categories = append(categories, category{ - Values: statsForFloats(sha256Perf), - Descr: "SHA-256 Hashing Performance", - Unit: "B/s", - Type: NumberBinary, - }) - - categories = append(categories, category{ - Values: statsForInts(numCPU), - Descr: "Number of CPU cores", - }) - - categories = append(categories, category{ - Values: statsForInts(uptime), - Descr: "Uptime (v3)", - Type: NumberDuration, - }) + categories := []category{ + { + Values: statsForInts(totFiles), + Descr: "Files Managed per Device", + }, { + Values: statsForInts(maxFiles), + Descr: "Files in Largest Folder", + }, { + Values: statsForInt64s(totMiB), + Descr: "Data Managed per Device", + Unit: "B", + Type: NumberBinary, + }, { + Values: statsForInt64s(maxMiB), + Descr: "Data in Largest Folder", + Unit: "B", + Type: NumberBinary, + }, { + Values: statsForInts(numDevices), + Descr: "Number of Devices in Cluster", + }, { + Values: statsForInts(numFolders), + Descr: "Number of Folders Configured", + }, { + Values: statsForInt64s(memoryUsage), + Descr: "Memory Usage", + Unit: "B", + Type: NumberBinary, + }, { + Values: statsForInt64s(memorySize), + Descr: "System Memory", + Unit: "B", + Type: NumberBinary, + }, { + Values: statsForFloats(sha256Perf), + Descr: "SHA-256 Hashing Performance", + Unit: "B/s", + Type: NumberBinary, + }, { + Values: statsForInts(numCPU), + Descr: "Number of CPU cores", + }, { + Values: statsForInts(uptime), + Descr: "Uptime (v3)", + Type: NumberDuration, + }, + } reportFeatures := make(map[string][]feature) for featureType, versions := range features { diff --git a/lib/model/sentdownloadstate.go b/lib/model/sentdownloadstate.go index 363a27ac1..3a5bcd702 100644 --- a/lib/model/sentdownloadstate.go +++ b/lib/model/sentdownloadstate.go @@ -80,18 +80,19 @@ func (s *sentFolderDownloadState) update(pullers []*sharedPullerState) []protoco if !pullerVersion.Equal(localFile.version) || !pullerCreated.Equal(localFile.created) { // The version has changed or the puller was reconstrcuted due to failure. // Clean up whatever we had for the old file, and advertise the new file. - updates = append(updates, protocol.FileDownloadProgressUpdate{ - Name: name, - Version: localFile.version, - UpdateType: protocol.FileDownloadProgressUpdateTypeForget, - }) - updates = append(updates, protocol.FileDownloadProgressUpdate{ - Name: name, - Version: pullerVersion, - UpdateType: protocol.FileDownloadProgressUpdateTypeAppend, - BlockIndexes: pullerBlockIndexes, - BlockSize: pullerBlockSize, - }) + updates = append(updates, + protocol.FileDownloadProgressUpdate{ + Name: name, + Version: localFile.version, + UpdateType: protocol.FileDownloadProgressUpdateTypeForget, + }, + protocol.FileDownloadProgressUpdate{ + Name: name, + Version: pullerVersion, + UpdateType: protocol.FileDownloadProgressUpdateTypeAppend, + BlockIndexes: pullerBlockIndexes, + BlockSize: pullerBlockSize, + }) localFile.blockIndexes = pullerBlockIndexes localFile.updated = pullerBlockIndexesUpdated localFile.version = pullerVersion