Compare commits

...

3 Commits

Author SHA1 Message Date
maru
fadd10602a
Don't log ErrNoRows in savedata 2024-05-09 14:26:54 -04:00
maru
e4de7c2391
Update database limiting code more 2024-05-09 14:22:20 -04:00
maru
de0bd74dc2
Update database limits 2024-05-09 14:13:19 -04:00
2 changed files with 14 additions and 4 deletions

View File

@ -18,6 +18,7 @@
package api
import (
"database/sql"
"encoding/json"
"fmt"
"net/http"
@ -280,6 +281,10 @@ func handleSaveData(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/savedata/get":
save, err = savedata.Get(uuid, datatype, slot)
if err == sql.ErrNoRows {
http.Error(w, err.Error(), http.StatusNotFound)
return
}
case "/savedata/update":
err = savedata.Update(uuid, slot, save)
case "/savedata/delete":

View File

@ -38,10 +38,15 @@ func Init(username, password, protocol, address, database string) error {
return fmt.Errorf("failed to open database connection: %s", err)
}
handle.SetMaxIdleConns(256)
handle.SetMaxOpenConns(256)
handle.SetConnMaxIdleTime(time.Second * 30)
handle.SetConnMaxLifetime(time.Minute)
conns := 1024
if protocol != "unix" {
conns = 256
}
handle.SetMaxOpenConns(conns)
handle.SetMaxIdleConns(conns/4)
handle.SetConnMaxIdleTime(time.Second * 10)
tx, err := handle.Begin()
if err != nil {