1
Fork 0

Reduce response time by using goroutine to update hit counter

This commit is contained in:
Jan-Lukas Else 2020-03-29 18:36:44 +02:00
parent 4d04abb778
commit 9a0ae07dfe
1 changed files with 7 additions and 10 deletions

17
main.go
View File

@ -218,16 +218,13 @@ func ShortenedUrlHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
stmt, err := db.Prepare("UPDATE redirect SET hits = hits + 1 WHERE slug = ?") go func() {
if err != nil { stmt, err := db.Prepare("UPDATE redirect SET hits = hits + 1 WHERE slug = ?")
http.Error(w, err.Error(), http.StatusInternalServerError) if err != nil {
return return
} }
_, err = stmt.Exec(slug) _, _ = stmt.Exec(slug)
if err != nil { }()
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Redirect(w, r, redirectUrl, http.StatusTemporaryRedirect) http.Redirect(w, r, redirectUrl, http.StatusTemporaryRedirect)
} }