diff --git a/db.go b/db.go index 5139ac6..9730f8e 100644 --- a/db.go +++ b/db.go @@ -9,9 +9,10 @@ import ( var Database = &advsql.Database{} var ( - InsertSession = advsql.Insert(Database, "INSERT INTO sessions VALUES (?, ?, ?)", ScanSessionPkFirst) - UpdateSession = advsql.Update(Database, "UPDATE sessions SET expiration_date = ?, creation_date = ? WHERE id = ?", ScanSessionPkLast) - GetSessionByID = advsql.QueryOne(Database, "SELECT * FROM sessions WHERE id = ?", ScanSessionPkFirst) + InsertSession = advsql.Insert(Database, "INSERT INTO sessions VALUES (?, ?, ?)", ScanSessionPkFirst) + UpdateSession = advsql.Update(Database, "UPDATE sessions SET expiration_date = ?, creation_date = ? WHERE id = ?", ScanSessionPkLast) + GetSessionByID = advsql.QueryOne(Database, "SELECT * FROM sessions WHERE id = ?", ScanSessionPkFirst) + DeleteSessionsByExpirationDateBefore = advsql.Delete(Database, "DELETE FROM sessions WHERE expiration_date <= ?") InsertBookmark = advsql.Insert(Database, "INSERT INTO bookmarks VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", ScanBookmarkPkFirst) UpdateBookmark = advsql.Update(Database, "UPDATE bookmarks SET link = ?, image = ?, color = ?, image_size = ?, icon_padding = ?, hide_border = ?, order_priority = ? WHERE session_id = ? AND title = ?", ScanBookmarkPkLast) diff --git a/main.go b/main.go index 04f14e9..0d38df3 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "net/http" "net/url" "strings" + "time" "git.milar.in/milarin/advsql" "git.milar.in/milarin/channel" @@ -50,6 +51,14 @@ func main() { r.HandleFunc("/search", search) r.PathPrefix("/static/").Handler(http.FileServer(http.FS(StaticFS))) + go func() { + for range time.Tick(time.Hour) { + if err := DeleteSessionsByExpirationDateBefore(time.Now()); err != nil { + fmt.Println("could not delete expired sessions", err) + } + } + }() + if err := http.ListenAndServe(fmt.Sprintf("%s:%d", envvars.String("HTTP_INTF", ""), envvars.Uint16("HTTP_PORT", 80)), r); err != nil { panic(err) }