Skip to content

Commit 217b5c1

Browse files
zeripathlunny
andauthored
Query the DB for the hash before inserting in to email_hash (#15457)
Some postgres users have logging which logs even failed transactions. So just query the db before trying to insert. Fix #15451 Signed-off-by: Andrew Thornton [email protected] Co-authored-by: Lunny Xiao <[email protected]>
1 parent f783004 commit 217b5c1

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

models/avatar.go

+5
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ func HashedAvatarLink(email string) string {
9696
// we don't care about any DB problem just return the lowerEmail
9797
return lowerEmail, nil
9898
}
99+
has, err := sess.Where("email = ? AND hash = ?", emailHash.Email, emailHash.Hash).Get(new(EmailHash))
100+
if has || err != nil {
101+
// Seriously we don't care about any DB problems just return the lowerEmail - we expect the transaction to fail most of the time
102+
return lowerEmail, nil
103+
}
99104
_, _ = sess.Insert(emailHash)
100105
if err := sess.Commit(); err != nil {
101106
// Seriously we don't care about any DB problems just return the lowerEmail - we expect the transaction to fail most of the time

0 commit comments

Comments
 (0)