Reduce response time by using goroutine to update hit counter
This commit is contained in:
parent
4d04abb778
commit
9a0ae07dfe
17
main.go
17
main.go
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue