فهرست منبع

history sync: store timestamp when the message got put into the DB

This will be useful for debugging issues with missing messages
Sumner Evans 3 سال پیش
والد
کامیت
17c697445d
2فایلهای تغییر یافته به همراه19 افزوده شده و 3 حذف شده
  1. 3 3
      database/historysync.go
  2. 16 0
      database/upgrades/2022-05-12-history-sync-message-add-added-timestamp.go

+ 3 - 3
database/historysync.go

@@ -249,10 +249,10 @@ func (hsq *HistorySyncQuery) NewMessageWithValues(userID id.UserID, conversation
 
 
 func (hsm *HistorySyncMessage) Insert() {
 func (hsm *HistorySyncMessage) Insert() {
 	_, err := hsm.db.Exec(`
 	_, err := hsm.db.Exec(`
-		INSERT INTO history_sync_message (user_mxid, conversation_id, message_id, timestamp, data)
-		VALUES ($1, $2, $3, $4, $5)
+		INSERT INTO history_sync_message (user_mxid, conversation_id, message_id, timestamp, data, inserted_time)
+		VALUES ($1, $2, $3, $4, $5, $6)
 		ON CONFLICT (user_mxid, conversation_id, message_id) DO NOTHING
 		ON CONFLICT (user_mxid, conversation_id, message_id) DO NOTHING
-	`, hsm.UserID, hsm.ConversationID, hsm.MessageID, hsm.Timestamp, hsm.Data)
+	`, hsm.UserID, hsm.ConversationID, hsm.MessageID, hsm.Timestamp, hsm.Data, time.Now())
 	if err != nil {
 	if err != nil {
 		hsm.log.Warnfln("Failed to insert history sync message %s/%s: %v", hsm.ConversationID, hsm.Timestamp, err)
 		hsm.log.Warnfln("Failed to insert history sync message %s/%s: %v", hsm.ConversationID, hsm.Timestamp, err)
 	}
 	}

+ 16 - 0
database/upgrades/2022-05-12-history-sync-message-add-added-timestamp.go

@@ -0,0 +1,16 @@
+package upgrades
+
+import (
+	"database/sql"
+)
+
+func init() {
+	upgrades[46] = upgrade{"Add inserted time to history sync message", func(tx *sql.Tx, ctx context) error {
+		// Add the inserted time TIMESTAMP column to history_sync_message
+		_, err := tx.Exec(`
+			ALTER TABLE history_sync_message
+			ADD COLUMN inserted_time TIMESTAMP
+		`)
+		return err
+	}}
+}