Skip to content

Commit

Permalink
Populate preallocated slice and use builder for strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jessepeterson committed Jul 15, 2021
1 parent 9516060 commit 52dd9ae
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions storage/mysql/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql"
"errors"
"fmt"
"strings"

"github.com/micromdm/nanomdm/mdm"
)
Expand All @@ -22,10 +23,11 @@ func enqueue(ctx context.Context, tx *sql.Tx, ids []string, cmd *mdm.Command) er
return err
}
query := `INSERT INTO enrollment_queue (id, command_uuid) VALUES (?, ?)`
args := []interface{}{ids[0], cmd.CommandUUID}
for _, id := range ids[1:] {
query += `, (?, ?)`
args = append(args, id, cmd.CommandUUID)
query += strings.Repeat(", (?, ?)", len(ids)-1)
args := make([]interface{}, len(ids)*2)
for i, id := range ids {
args[i*2] = id
args[i*2+1] = cmd.CommandUUID
}
_, err = tx.ExecContext(ctx, query+";", args...)
return err
Expand Down

0 comments on commit 52dd9ae

Please sign in to comment.