everfid-ever commented on code in PR #1018:
URL: 
https://github.com/apache/incubator-seata-go/pull/1018#discussion_r2594521960


##########
pkg/datasource/sql/undo/executor/executor.go:
##########
@@ -168,21 +168,33 @@ func (b *BaseExecutor) queryCurrentRecords(ctx 
context.Context, conn *sql.Conn)
 }
 
 func (b *BaseExecutor) parsePkValues(rows []types.RowImage, pkNameList 
[]string) map[string][]types.ColumnImage {
-       pkValues := make(map[string][]types.ColumnImage)
-       // todo optimize 3 fors
+       if len(rows) == 0 {
+               return make(map[string][]types.ColumnImage)
+       }
+
+       pkLookup := make(map[string]string, len(pkNameList))
+       for _, pk := range pkNameList {
+               pkLookup[strings.ToLower(pk)] = pk
+       }
+
+       pkValues := make(map[string][]types.ColumnImage, len(pkNameList))
+       for _, pk := range pkNameList {
+               pkValues[pk] = make([]types.ColumnImage, 0, len(rows))
+       }
+
        for _, row := range rows {
                for _, column := range row.Columns {
-                       for _, pk := range pkNameList {
-                               if strings.EqualFold(pk, column.ColumnName) {
-                                       values := pkValues[strings.ToUpper(pk)]
-                                       if values == nil {
-                                               values = 
make([]types.ColumnImage, 0)
-                                       }
-                                       values = append(values, column)
-                                       pkValues[pk] = values
-                               }
+                       if originalPk, exists := 
pkLookup[strings.ToLower(column.ColumnName)]; exists {
+                               pkValues[originalPk] = 
append(pkValues[originalPk], column)
                        }
                }
        }
+
+       for pk, values := range pkValues {

Review Comment:
   Thanks for your suggestion, I have optimized the method as suggested.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to