Skip to content

Commit

Permalink
Instead of counting messages left on broadcasts, just check if any exist
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Jan 6, 2023
1 parent bae126e commit 4fd0122
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions archives/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,20 +261,19 @@ func DeleteBroadcasts(ctx context.Context, now time.Time, config *Config, db *sq
}

var broadcastID int64
err := rows.Scan(&broadcastID)
if err != nil {
if err := rows.Scan(&broadcastID); err != nil {
return errors.Wrap(err, "unable to get broadcast id")
}

// make sure we have no active messages
var msgCount int64
err = db.Get(&msgCount, `SELECT count(*) FROM msgs_msg WHERE broadcast_id = $1`, broadcastID)
// make sure we have no messages left
var hasMsgs bool
err = db.Get(&hasMsgs, `SELECT EXISTS(SELECT 1 FROM msgs_msg WHERE broadcast_id = $1)`, broadcastID)
if err != nil {
return errors.Wrapf(err, "unable to select number of msgs for broadcast: %d", broadcastID)
return errors.Wrapf(err, "error checking if broadcast still has messages: %d", broadcastID)
}

if msgCount != 0 {
logrus.WithField("broadcast_id", broadcastID).WithField("org_id", org.ID).WithField("msg_count", msgCount).Warn("unable to delete broadcast, has messages still")
if hasMsgs {
logrus.WithField("broadcast_id", broadcastID).WithField("org_id", org.ID).Warn("unable to delete broadcast, has messages still")
continue
}

Expand Down

0 comments on commit 4fd0122

Please sign in to comment.