Skip to content

Commit

Permalink
Count messages that failed to save
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Mar 12, 2024
1 parent 46420c1 commit fee357b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion historysync.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ func (user *User) storeHistorySync(evt *waProto.HistorySync) {
Msg("Storing history sync")

successfullySavedTotal := 0
failedToSaveTotal := 0
totalMessageCount := 0
for _, conv := range evt.GetConversations() {
jid, err := types.ParseJID(conv.GetId())
Expand Down Expand Up @@ -578,6 +579,7 @@ func (user *User) storeHistorySync(evt *waProto.HistorySync) {
var minTimeIndex, maxTimeIndex int

successfullySaved := 0
failedToSave := 0
unsupportedTypes := 0
for i, rawMsg := range conv.GetMessages() {
// Don't store messages that will just be skipped.
Expand Down Expand Up @@ -614,6 +616,7 @@ func (user *User) storeHistorySync(evt *waProto.HistorySync) {
Str("msg_id", msgEvt.Info.ID).
Time("msg_time", msgEvt.Info.Timestamp).
Msg("Failed to save historical message")
failedToSave++
continue
}
err = message.Insert(ctx)
Expand All @@ -623,12 +626,16 @@ func (user *User) storeHistorySync(evt *waProto.HistorySync) {
Str("msg_id", msgEvt.Info.ID).
Time("msg_time", msgEvt.Info.Timestamp).
Msg("Failed to save historical message")
failedToSave++
} else {
successfullySaved++
}
successfullySaved++
}
successfullySavedTotal += successfullySaved
failedToSaveTotal += failedToSave
log.Debug().
Int("saved_count", successfullySaved).
Int("failed_count", failedToSave).
Int("unsupported_msg_type_count", unsupportedTypes).
Time("lowest_time", minTime).
Int("lowest_time_index", minTimeIndex).
Expand All @@ -646,6 +653,7 @@ func (user *User) storeHistorySync(evt *waProto.HistorySync) {
}
log.Info().
Int("total_saved_count", successfullySavedTotal).
Int("total_failed_count", failedToSaveTotal).
Int("total_message_count", totalMessageCount).
Msg("Finished storing history sync")

Expand Down

0 comments on commit fee357b

Please sign in to comment.