signalmeow/store: add logs for recipient updates

This commit is contained in:
Tulir Asokan 2025-01-30 18:11:06 +02:00
parent 0ca656a5e1
commit f07723070d

View file

@ -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"
@ -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
}
@ -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)
@ -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)