]> source.dussan.org Git - gitea.git/commitdiff
Query the DB for the hash before inserting in to email_hash (#15457)
authorzeripath <art27@cantab.net>
Thu, 15 Apr 2021 12:22:04 +0000 (13:22 +0100)
committerGitHub <noreply@github.com>
Thu, 15 Apr 2021 12:22:04 +0000 (13:22 +0100)
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>
models/avatar.go

index 166ca337ca2627fe127533c4c2433907ce86c706..ad1e19d0d7cd06bade12cb749e2a29f46d6149c3 100644 (file)
@@ -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