feat: add message size

This commit is contained in:
Richard Ramos 2023-02-01 11:36:18 -04:00 committed by RichΛrd
parent 859822226d
commit d9715f3d8b
3 changed files with 11 additions and 7 deletions

View File

@ -1,7 +1,7 @@
// Code generated by go-bindata. DO NOT EDIT.
// sources:
// 000001_message_type.up.sql (66B)
// 000002_bandwidth_protocol.up.sql (657B)
// 000002_bandwidth_protocol.up.sql (719B)
// doc.go (73B)
package telemetry
@ -91,7 +91,7 @@ func _000001_message_typeUpSql() (*asset, error) {
return a, nil
}
var __000002_bandwidth_protocolUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xbc\x90\x4f\x4b\xc4\x30\x10\xc5\xef\xfd\x14\x73\x6c\xa1\x27\x61\x4f\x9e\x62\x77\xd4\xc1\x9a\x2e\x93\xac\xb8\x27\x09\xdb\x80\x85\x35\xd1\x76\xfa\xfd\xa5\x0d\x2a\xfe\xd9\x2a\x1e\xf6\x94\xc3\x7b\xcc\xcb\xef\x57\x31\x2a\x8b\x60\xd5\x45\x8d\x40\x97\xa0\x1b\x0b\x78\x4f\xc6\x1a\x78\xee\xa3\xc4\x7d\x3c\x18\x71\x32\xb0\x13\x0f\x79\x06\x00\xd0\xb5\x60\x90\x49\xd5\xb0\x61\xba\x55\xbc\x83\x1b\xdc\x95\x73\xf4\x18\x07\xa1\x16\xee\x14\x57\xd7\x8a\xf3\xb3\xd5\xaa\x98\x2f\xea\x6d\x5d\xa7\xc6\xdb\x51\xed\x9e\xfc\x52\xaf\x77\xe2\x29\xc0\xba\xd9\x4e\x1f\xdb\x30\x56\x64\xa8\xd1\x3f\xb4\x9a\x51\x7e\xab\xed\x7b\xef\xc4\xb7\x4a\x80\xb4\xc5\x2b\xe4\xaf\x79\x0c\x83\xf4\xae\x0b\xf2\x1d\xfa\x61\x0c\xdd\xcb\xe8\x21\x3d\x79\x22\x2c\x3f\x71\x94\x1f\x03\x45\x56\x9c\x67\xd9\x5f\xa5\xda\x28\xee\x30\x9c\x52\xab\x4c\x8b\x14\x8e\x78\x98\xd3\xc9\xe7\x11\x4d\xef\x1a\xd7\xca\xe2\xb2\xba\x84\xf6\x0f\x79\xaf\x01\x00\x00\xff\xff\xd6\x24\x1d\x9b\x91\x02\x00\x00")
var __000002_bandwidth_protocolUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xbc\x90\x3f\x4f\xf3\x30\x10\xc6\xf7\x7c\x8a\x1b\x5b\x29\xd3\x2b\x75\xea\xe4\x37\x39\xc0\xc2\x71\x2a\xdb\x41\x74\x42\x56\x72\x82\x48\x6d\x0c\xf1\x85\x81\x4f\x8f\x92\x50\x10\x7f\x5a\x10\x03\x93\x25\x3f\x8f\xee\xee\xf7\xcb\x0c\x0a\x87\xe0\xc4\x7f\x85\x20\xcf\x40\x97\x0e\xf0\x5a\x5a\x67\xe1\xbe\x0f\x1c\xea\xb0\xb3\xec\x39\x1a\xcf\x04\x8b\x04\x00\xa0\x6d\xc0\xa2\x91\x42\xc1\xc6\xc8\x42\x98\x2d\x5c\xe2\x36\x9d\xa2\xbb\x10\x59\x36\x70\x25\x4c\x76\x21\xcc\xe2\xdf\x6a\xb5\x9c\x26\xea\x4a\xa9\xb9\x71\x18\xaa\xfd\x9e\x4e\xf5\x7a\xcf\x24\x3b\xc8\xcb\x6a\x3c\x6c\x63\x30\x93\x56\x96\xfa\x8b\x56\x39\xf0\x77\xb5\xba\x27\xcf\xd4\x08\x06\xa9\x1d\x9e\xa3\xf9\x98\x87\x2e\x72\xef\xdb\x8e\x3f\x43\xdf\x0c\x5d\xfb\x30\x10\xcc\xcf\x62\x26\x4c\xdf\x71\xa4\x6f\x0b\x96\xc9\x72\x9d\x24\x3f\x95\xea\x02\xfb\x5d\xfc\x4b\xad\x3c\x6e\x94\xdd\x11\x0f\x53\x3a\xfa\x3c\xa2\xe9\x55\x63\x2e\x1c\x9e\x56\x37\xa3\xfd\x46\x9e\x50\x0e\xcd\x8b\xbb\x9e\x6a\x6a\x1f\xa9\x29\x28\x46\x7f\x4b\x11\x44\x9e\x43\x56\xaa\xaa\xd0\xb0\x9f\xff\x6c\xfb\x44\x87\x7b\xd7\xc9\x73\x00\x00\x00\xff\xff\x88\xcb\xe5\x75\xcf\x02\x00\x00")
func _000002_bandwidth_protocolUpSqlBytes() ([]byte, error) {
return bindataRead(
@ -106,8 +106,8 @@ func _000002_bandwidth_protocolUpSql() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "000002_bandwidth_protocol.up.sql", size: 657, mode: os.FileMode(0664), modTime: time.Unix(1675204316, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x82, 0x33, 0x32, 0x3e, 0xa6, 0x35, 0x56, 0x34, 0xa1, 0xe7, 0x90, 0x7, 0x9b, 0x6a, 0xa1, 0x5d, 0xfe, 0xf, 0xe4, 0x26, 0xec, 0xb6, 0x20, 0x9, 0xa9, 0x61, 0x78, 0x87, 0xfd, 0x14, 0xbf, 0x1c}}
info := bindataFileInfo{name: "000002_bandwidth_protocol.up.sql", size: 719, mode: os.FileMode(0664), modTime: time.Unix(1675262994, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xfe, 0x83, 0x69, 0xab, 0x3e, 0xf5, 0x8d, 0x44, 0xb2, 0x6e, 0x52, 0x8d, 0x27, 0xe8, 0x95, 0x28, 0x3c, 0xea, 0x29, 0x93, 0x6d, 0xa3, 0x10, 0xde, 0x9b, 0xc8, 0xa6, 0xb9, 0x80, 0xa1, 0x3, 0x6f}}
return a, nil
}

View File

@ -20,6 +20,7 @@ type ReceivedMessage struct {
MessageHash string `json:"messageHash"`
MessageID string `json:"messageId"`
MessageType string `json:"messageType"`
MessageSize int `json:"messageSize"`
ReceiverKeyUID string `json:"receiverKeyUID"`
NodeName string `json:"nodeName"`
SentAt int64 `json:"sentAt"`
@ -28,7 +29,7 @@ type ReceivedMessage struct {
}
func queryReceivedMessagesBetween(db *sql.DB, startsAt time.Time, endsAt time.Time) ([]*ReceivedMessage, error) {
rows, err := db.Query(fmt.Sprintf("SELECT id, chatId, messageHash, messageId, receiverKeyUID, nodeName, sentAt, topic, messageType, createdAt FROM receivedMessages WHERE sentAt BETWEEN %d and %d", startsAt.Unix(), endsAt.Unix()))
rows, err := db.Query(fmt.Sprintf("SELECT id, chatId, messageHash, messageId, receiverKeyUID, nodeName, sentAt, topic, messageType, messageSize, createdAt FROM receivedMessages WHERE sentAt BETWEEN %d and %d", startsAt.Unix(), endsAt.Unix()))
if err != nil {
return nil, err
}
@ -47,6 +48,7 @@ func queryReceivedMessagesBetween(db *sql.DB, startsAt time.Time, endsAt time.Ti
&receivedMessage.SentAt,
&receivedMessage.Topic,
&receivedMessage.MessageType,
&receivedMessage.MessageSize,
&receivedMessage.CreatedAt,
)
if err != nil {
@ -84,14 +86,14 @@ func didReceivedMessageBeforeAndAfterInChat(db *sql.DB, receiverPublicKey string
}
func (r *ReceivedMessage) put(db *sql.DB) error {
stmt, err := db.Prepare("INSERT INTO receivedMessages (chatId, messageHash, messageId, receiverKeyUID, nodeName, sentAt, topic, messageType, createdAt) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING id;")
stmt, err := db.Prepare("INSERT INTO receivedMessages (chatId, messageHash, messageId, receiverKeyUID, nodeName, sentAt, topic, messageType, messageSize, createdAt) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING id;")
if err != nil {
return err
}
r.CreatedAt = time.Now().Unix()
lastInsertId := 0
err = stmt.QueryRow(r.ChatID, r.MessageHash, r.MessageID, r.ReceiverKeyUID, r.NodeName, r.SentAt, r.Topic, r.MessageType, r.CreatedAt).Scan(&lastInsertId)
err = stmt.QueryRow(r.ChatID, r.MessageHash, r.MessageID, r.ReceiverKeyUID, r.NodeName, r.SentAt, r.Topic, r.MessageType, r.MessageSize, r.CreatedAt).Scan(&lastInsertId)
if err != nil {
return err
}

View File

@ -17,3 +17,5 @@ CREATE TABLE IF NOT EXISTS protocolStatsTotals (
createdAt DATE,
constraint protocolStatsTotals_unique unique(hostId, protocolName, createdAt)
);
ALTER TABLE receivedMessages ADD COLUMN messageSize INTEGER;