You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2020/02/20 21:29:16 UTC

[GitHub] [trafficcontrol] rob05c commented on a change in pull request #4419: ORT Speed Improvements

rob05c commented on a change in pull request #4419: ORT Speed Improvements
URL: https://github.com/apache/trafficcontrol/pull/4419#discussion_r382267890
 
 

 ##########
 File path: traffic_ops/ort/atstccfg/toreq/caching.go
 ##########
 @@ -177,3 +215,65 @@ func GetCookiesFromFile(tempDir string, cacheFileMaxAge time.Duration) (string,
 	}
 	return string(bts), nil
 }
+
+// DSSExtension is the file extension for the format read and written by DSSEncode and DSSDecode.
+const DSSExtension = ".csv"
+
+// DSSEncode is an EncodeFunc optimized for Delivery Service Servers.
+// If iObj is not a *[]tc.DeliveryServiceServer it immediately returns an error.
+func DSSEncode(w io.Writer, iObj interface{}) error {
+	// Please don't change this to use encoding/csv unless you benchmark and prove it's at least as fast. DSS is massive, and performance is important.
+	obj, ok := iObj.(*[]tc.DeliveryServiceServer)
+	if !ok {
+		return fmt.Errorf("object is '%T' must be a *[]tc.DeliveryServiceServer\n", iObj)
+	}
+	for _, dss := range *obj {
+		if dss.DeliveryService == nil || dss.Server == nil {
+			continue // TODO warn?
+		}
+		if _, err := io.WriteString(w, strconv.Itoa(*dss.DeliveryService)+`,`+strconv.Itoa(*dss.Server)+"\n"); err != nil {
+			return fmt.Errorf("writing object cache file: " + err.Error())
+		}
+	}
+	return nil
+}
+
+// DSSDecode is a DecodeFunc optimized for Delivery Service Servers.
+// If iObj is not a *[]tc.DeliveryServiceServer it immediately returns an error.
+func DSSDecode(r io.Reader, iObj interface{}) error {
+	// Please don't change this to use encoding/csv unless you benchmark and prove it's at least as fast. DSS is massive, and performance is important.
+	obj, ok := iObj.(*[]tc.DeliveryServiceServer)
+	if !ok {
+		return fmt.Errorf("object is '%T' must be a *[]tc.DeliveryServiceServer\n", iObj)
+	}
+	objFileReader := bufio.NewReader(r)
+	for {
+		dsStr, err := objFileReader.ReadString(',')
 
 Review comment:
   There's no `[]byte` to int conversion func in Go.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services