Skip to content

Commit

Permalink
signalmeow: fix edge case in LoadAndUpdateRecipient
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jun 25, 2024
1 parent 43ee1bb commit 0c82b56
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/signalmeow/store/recipient_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ func (s *sqlStore) LoadAndUpdateRecipient(ctx context.Context, aci, pni uuid.UUI
if err != nil {
return fmt.Errorf("failed to run updater function: %w", err)
}
// SQL only supports one ON CONFLICT clause, which means StoreRecipient will key on the ACI if it's present.
// If we're adding an ACI to a PNI row, just delete the PNI row first to avoid conflicts on the PNI key.
if outRecipient.PNI != uuid.Nil && outRecipient.ACI == uuid.Nil && aci != uuid.Nil {
err = s.DeleteRecipientByPNI(ctx, outRecipient.PNI)
if err != nil {
return fmt.Errorf("failed to delete old PNI row: %w", err)
}
}
if outRecipient.PNI == uuid.Nil && pni != uuid.Nil {
outRecipient.PNI = pni
changed = true
Expand Down

0 comments on commit 0c82b56

Please sign in to comment.