Skip to content

Commit 55023a6

Browse files
author
Jeff Yanta
committed
Revert "Improvements to Twitter registration DB transaction (#108)"
This reverts commit acbd122.
1 parent acbd122 commit 55023a6

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

pkg/code/async/user/twitter.go

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -124,38 +124,34 @@ func (p *service) processNewTwitterRegistrations(ctx context.Context) error {
124124
}
125125

126126
// Save the updated tipping information
127-
var isRegistered bool
128127
err = p.data.ExecuteInTx(ctx, sql.LevelDefault, func(ctx context.Context) error {
129-
var isNonceUsed bool
130128
err = p.data.MarkTwitterNonceAsUsed(ctx, tweet.ID, *registrationNonce)
131-
switch err {
132-
case nil:
133-
case twitter.ErrDuplicateNonce:
134-
isNonceUsed = true
135-
default:
129+
if err != nil {
136130
return err
137131
}
138132

139-
// Only save updated tip addresses when the nonce isn't used
140-
if !isNonceUsed {
141-
err = p.updateCachedTwitterUser(ctx, tweet.AdditionalMetadata.Author, tipAccount)
142-
switch err {
143-
case nil:
144-
isRegistered = true
145-
case twitter.ErrDuplicateTipAddress:
146-
default:
147-
return err
148-
}
133+
err = p.updateCachedTwitterUser(ctx, tweet.AdditionalMetadata.Author, tipAccount)
134+
if err != nil {
135+
return err
149136
}
150137

151-
return p.data.MarkTweetAsProcessed(ctx, tweet.ID)
138+
err = p.data.MarkTweetAsProcessed(ctx, tweet.ID)
139+
if err != nil {
140+
return err
141+
}
142+
143+
return nil
152144
})
153-
if err != nil {
154-
return errors.Wrap(err, "error saving registration details")
155-
}
156145

157-
if isRegistered {
146+
switch err {
147+
case nil:
158148
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
153+
default:
154+
return errors.Wrap(err, "error saving new registration")
159155
}
160156
}
161157

0 commit comments

Comments
 (0)