summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-04-15 14:29:13 +0100
committerGitHub <noreply@github.com>2021-04-15 09:29:13 -0400
commit85880b2a0ba4d63d0968c54b73c37c9a1b63a44e (patch)
treeb0b2a198f27f85273f51e758a34cf40b79cd6571
parent211bb911e3ec2ccf3fb005da07208fd77e932318 (diff)
downloadgitea-85880b2a0ba4d63d0968c54b73c37c9a1b63a44e.tar.gz
gitea-85880b2a0ba4d63d0968c54b73c37c9a1b63a44e.zip
Query the DB for the hash before inserting in to email_hash (#15457) (#15491)
Backport #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 art27@cantab.net Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
-rw-r--r--models/avatar.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/models/avatar.go b/models/avatar.go
index 166ca337ca..ad1e19d0d7 100644
--- a/models/avatar.go
+++ b/models/avatar.go
@@ -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