Skip to content

Commit

Permalink
Query the DB for the hash before inserting in to email_hash (go-gitea…
Browse files Browse the repository at this point in the history
…#15457)

Backport go-gitea#15457

Some postgres users have logging which logs even failed transactions. So
just query the db before trying to insert.

Fix go-gitea#15451

Signed-off-by: Andrew Thornton art27@cantab.net
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
  • Loading branch information
zeripath and lunny committed Apr 15, 2021
1 parent 211bb91 commit aa9b29c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions models/avatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ func HashedAvatarLink(email string) string {
// we don't care about any DB problem just return the lowerEmail
return lowerEmail, nil
}
has, err := sess.Where("email = ? AND hash = ?", emailHash.Email, emailHash.Hash).Get(new(EmailHash))
if has || err != nil {
// Seriously we don't care about any DB problems just return the lowerEmail - we expect the transaction to fail most of the time
return lowerEmail, nil
}
_, _ = sess.Insert(emailHash)
if err := sess.Commit(); err != nil {
// Seriously we don't care about any DB problems just return the lowerEmail - we expect the transaction to fail most of the time
Expand Down

0 comments on commit aa9b29c

Please sign in to comment.