@@ -25,6 +25,7 @@ import (
25
25
"time"
26
26
27
27
"github.com/google/uuid"
28
+ "github.com/rs/zerolog"
28
29
"go.mau.fi/util/dbutil"
29
30
30
31
"go.mau.fi/mautrix-signal/pkg/libsignalgo"
@@ -166,6 +167,10 @@ func (s *sqlStore) mergeRecipients(ctx context.Context, first, second *types.Rec
166
167
first , second = second , first
167
168
}
168
169
first .PNI = second .PNI
170
+ zerolog .Ctx (ctx ).Debug ().
171
+ Stringer ("aci" , first .ACI ).
172
+ Stringer ("pni" , first .PNI ).
173
+ Msg ("Merging recipient entries in database" )
169
174
if second .E164 != "" {
170
175
first .E164 = second .E164
171
176
}
@@ -247,6 +252,10 @@ func (s *sqlStore) LoadAndUpdateRecipient(ctx context.Context, aci, pni uuid.UUI
247
252
// SQL only supports one ON CONFLICT clause, which means StoreRecipient will key on the ACI if it's present.
248
253
// If we're adding an ACI to a PNI row, just delete the PNI row first to avoid conflicts on the PNI key.
249
254
if outRecipient .PNI != uuid .Nil && outRecipient .ACI == uuid .Nil && aci != uuid .Nil {
255
+ zerolog .Ctx (ctx ).Debug ().
256
+ Stringer ("aci" , outRecipient .ACI ).
257
+ Stringer ("pni" , outRecipient .PNI ).
258
+ Msg ("Deleting old PNI-only row before inserting row with both IDs" )
250
259
err = s .DeleteRecipientByPNI (ctx , outRecipient .PNI )
251
260
if err != nil {
252
261
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
261
270
changed = true
262
271
}
263
272
if changed || len (entries ) == 0 {
273
+ zerolog .Ctx (ctx ).Trace ().
274
+ Stringer ("aci" , outRecipient .ACI ).
275
+ Stringer ("pni" , outRecipient .PNI ).
276
+ Msg ("Saving recipient row" )
264
277
err = s .StoreRecipient (ctx , outRecipient )
265
278
if err != nil {
266
279
return fmt .Errorf ("failed to store updated recipient row: %w" , err )
0 commit comments