1
0
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:
fuzhy 2022-04-26 14:57:02 +08:00 committed by GitHub
parent 92d8fb99bf
commit 188778710f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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()