Skip to content

Commit

Permalink
signalmeow/store: add logs for recipient updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jan 30, 2025
1 parent 0ca656a commit f077230
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/signalmeow/store/recipient_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"time"

"github.com/google/uuid"
"github.com/rs/zerolog"
"go.mau.fi/util/dbutil"

"go.mau.fi/mautrix-signal/pkg/libsignalgo"
Expand Down Expand Up @@ -166,6 +167,10 @@ func (s *sqlStore) mergeRecipients(ctx context.Context, first, second *types.Rec
first, second = second, first
}
first.PNI = second.PNI
zerolog.Ctx(ctx).Debug().
Stringer("aci", first.ACI).
Stringer("pni", first.PNI).
Msg("Merging recipient entries in database")
if second.E164 != "" {
first.E164 = second.E164
}
Expand Down Expand Up @@ -247,6 +252,10 @@ func (s *sqlStore) LoadAndUpdateRecipient(ctx context.Context, aci, pni uuid.UUI
// 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 {
zerolog.Ctx(ctx).Debug().
Stringer("aci", outRecipient.ACI).
Stringer("pni", outRecipient.PNI).
Msg("Deleting old PNI-only row before inserting row with both IDs")
err = s.DeleteRecipientByPNI(ctx, outRecipient.PNI)
if err != nil {
return fmt.Errorf("failed to delete old PNI row: %w", err)
Expand All @@ -261,6 +270,10 @@ func (s *sqlStore) LoadAndUpdateRecipient(ctx context.Context, aci, pni uuid.UUI
changed = true
}
if changed || len(entries) == 0 {
zerolog.Ctx(ctx).Trace().
Stringer("aci", outRecipient.ACI).
Stringer("pni", outRecipient.PNI).
Msg("Saving recipient row")
err = s.StoreRecipient(ctx, outRecipient)
if err != nil {
return fmt.Errorf("failed to store updated recipient row: %w", err)
Expand Down

0 comments on commit f077230

Please sign in to comment.