Fix some checks

This commit is contained in:
Tulir Asokan 2023-07-12 02:49:27 +03:00
parent 1f45d5bdec
commit e1603932aa

View file

@ -50,24 +50,26 @@ func (portal *Portal) missedForwardBackfill(user *User, lastMessageTS time.Time,
Str("action", "missed forward backfill"). Str("action", "missed forward backfill").
Logger() Logger()
ctx := log.WithContext(context.TODO()) ctx := log.WithContext(context.TODO())
if portal.lastMessageTS.IsZero() { if !lastMessageTS.IsZero() {
lastMsg, err := portal.bridge.DB.Message.GetLastInChat(ctx, portal.Key) if portal.lastMessageTS.IsZero() {
if err != nil { lastMsg, err := portal.bridge.DB.Message.GetLastInChat(ctx, portal.Key)
log.Err(err).Msg("Failed to get last message in chat") if err != nil {
return log.Err(err).Msg("Failed to get last message in chat")
} else if lastMsg == nil { return
log.Debug().Msg("No messages in chat") } else if lastMsg == nil {
} else { log.Debug().Msg("No messages in chat")
portal.lastMessageTS = lastMsg.Timestamp } else {
portal.lastMessageTS = lastMsg.Timestamp
}
}
if !lastMessageTS.After(portal.lastMessageTS) {
log.Trace().
Time("latest_message_ts", lastMessageTS).
Str("latest_message_id", lastMessageID).
Time("last_bridged_ts", portal.lastMessageTS).
Msg("Nothing to backfill")
return
} }
}
if !lastMessageTS.After(portal.lastMessageTS) {
log.Trace().
Time("latest_message_ts", lastMessageTS).
Str("latest_message_id", lastMessageID).
Time("last_bridged_ts", portal.lastMessageTS).
Msg("Nothing to backfill")
return
} }
log.Info(). log.Info().
Time("latest_message_ts", lastMessageTS). Time("latest_message_ts", lastMessageTS).
@ -115,6 +117,10 @@ func (portal *Portal) forwardBackfill(ctx context.Context, user *User, after tim
} }
} }
} }
if len(converted) == 0 {
log.Debug().Msg("Didn't get any converted messages")
return
}
log.Debug(). log.Debug().
Int("converted_count", len(converted)). Int("converted_count", len(converted)).
Msg("Converted messages for backfill") Msg("Converted messages for backfill")