delete old sessions
This commit is contained in:
parent
f75720e0ec
commit
12298408da
7
db.go
7
db.go
@ -9,9 +9,10 @@ import (
|
|||||||
var Database = &advsql.Database{}
|
var Database = &advsql.Database{}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
InsertSession = advsql.Insert(Database, "INSERT INTO sessions VALUES (?, ?, ?)", ScanSessionPkFirst)
|
InsertSession = advsql.Insert(Database, "INSERT INTO sessions VALUES (?, ?, ?)", ScanSessionPkFirst)
|
||||||
UpdateSession = advsql.Update(Database, "UPDATE sessions SET expiration_date = ?, creation_date = ? WHERE id = ?", ScanSessionPkLast)
|
UpdateSession = advsql.Update(Database, "UPDATE sessions SET expiration_date = ?, creation_date = ? WHERE id = ?", ScanSessionPkLast)
|
||||||
GetSessionByID = advsql.QueryOne(Database, "SELECT * FROM sessions WHERE id = ?", ScanSessionPkFirst)
|
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)
|
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)
|
UpdateBookmark = advsql.Update(Database, "UPDATE bookmarks SET link = ?, image = ?, color = ?, image_size = ?, icon_padding = ?, hide_border = ?, order_priority = ? WHERE session_id = ? AND title = ?", ScanBookmarkPkLast)
|
||||||
|
9
main.go
9
main.go
@ -9,6 +9,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.milar.in/milarin/advsql"
|
"git.milar.in/milarin/advsql"
|
||||||
"git.milar.in/milarin/channel"
|
"git.milar.in/milarin/channel"
|
||||||
@ -50,6 +51,14 @@ func main() {
|
|||||||
r.HandleFunc("/search", search)
|
r.HandleFunc("/search", search)
|
||||||
r.PathPrefix("/static/").Handler(http.FileServer(http.FS(StaticFS)))
|
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 {
|
if err := http.ListenAndServe(fmt.Sprintf("%s:%d", envvars.String("HTTP_INTF", ""), envvars.Uint16("HTTP_PORT", 80)), r); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user