Skip to content

Commit 3156971

Browse files
authored
Improve Twitter registration when detecting duplicates (#109)
1 parent 55023a6 commit 3156971

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

pkg/code/async/user/twitter.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,21 +135,31 @@ func (p *service) processNewTwitterRegistrations(ctx context.Context) error {
135135
return err
136136
}
137137

138-
err = p.data.MarkTweetAsProcessed(ctx, tweet.ID)
139-
if err != nil {
140-
return err
141-
}
142-
143-
return nil
138+
return p.data.MarkTweetAsProcessed(ctx, tweet.ID)
144139
})
145140

146141
switch err {
147142
case nil:
148143
go push_util.SendTwitterAccountConnectedPushNotification(ctx, p.data, p.pusher, tipAccount)
149-
case twitter.ErrDuplicateTipAddress, twitter.ErrDuplicateNonce:
150-
// Any race conditions with duplicate nonces or tip addresses will are ignored
151-
//
152-
// todo: In the future, support multiple tip address mappings
144+
case twitter.ErrDuplicateTipAddress:
145+
err = p.data.ExecuteInTx(ctx, sql.LevelDefault, func(ctx context.Context) error {
146+
err = p.data.MarkTwitterNonceAsUsed(ctx, tweet.ID, *registrationNonce)
147+
if err != nil {
148+
return err
149+
}
150+
151+
return p.data.MarkTweetAsProcessed(ctx, tweet.ID)
152+
})
153+
if err != nil {
154+
return errors.Wrap(err, "error saving tweet with duplicate tip address metadata")
155+
}
156+
return nil
157+
case twitter.ErrDuplicateNonce:
158+
err = p.data.MarkTweetAsProcessed(ctx, tweet.ID)
159+
if err != nil {
160+
return errors.Wrap(err, "error marking tweet with duplicate nonce as processed")
161+
}
162+
return nil
153163
default:
154164
return errors.Wrap(err, "error saving new registration")
155165
}

0 commit comments

Comments
 (0)