mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-24 13:48:49 +08:00
NOISSUE - Move invariant statements out of loop for cassandra-writer (#1596)
Signed-off-by: fuzhy <fuzhy1997@outlook.com>
This commit is contained in:
parent
92d8fb99bf
commit
188778710f
@ -75,13 +75,13 @@ func (cr *cassandraRepository) saveJSON(msgs mfjson.Messages) error {
|
||||
}
|
||||
|
||||
func (cr *cassandraRepository) insertJSON(msgs mfjson.Messages) error {
|
||||
cql := `INSERT INTO %s (id, channel, created, subtopic, publisher, protocol, payload) VALUES (?, ?, ?, ?, ?, ?, ?)`
|
||||
cql = fmt.Sprintf(cql, msgs.Format)
|
||||
for _, msg := range msgs.Data {
|
||||
pld, err := json.Marshal(msg.Payload)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cql := `INSERT INTO %s (id, channel, created, subtopic, publisher, protocol, payload) VALUES (?, ?, ?, ?, ?, ?, ?)`
|
||||
cql = fmt.Sprintf(cql, msgs.Format)
|
||||
id := gocql.TimeUUID()
|
||||
|
||||
err = cr.session.Query(cql, id, msg.Channel, msg.Created, msg.Subtopic, msg.Publisher, msg.Protocol, string(pld)).Exec()
|
||||
|
Loading…
x
Reference in New Issue
Block a user