increase session cacche ttl

peertube
Namekuji 2023-01-29 21:30:10 -05:00
rodzic db42f13ee4
commit 150ad6df05
4 zmienionych plików z 4 dodań i 5 usunięć

Wyświetl plik

@ -8,6 +8,7 @@ import (
"strings"
"time"
"github.com/jellydator/ttlcache/v3"
"github.com/labstack/echo/v4"
mastodon "github.com/mattn/go-mastodon"
"github.com/oklog/ulid/v2"
@ -228,6 +229,7 @@ func authMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
data, err := getSessionData(c)
if err == nil && data.AudonID != "" {
if user, err := findUserByID(c.Request().Context(), data.AudonID); err == nil {
userSessionCache.Set(data.AudonID, data, ttlcache.DefaultTTL)
c.Set("user", user)
c.Set("data", data)
return next(c)

Wyświetl plik

@ -415,8 +415,6 @@ func joinRoomHandler(c echo.Context) (err error) {
}
// Store user's session data in cache
data, _ := getSessionData(c)
userSessionCache.Set(user.AudonID, data, ttlcache.DefaultTTL)
orphanRooms.Delete(roomID)
return c.JSON(http.StatusOK, resp)

Wyświetl plik

@ -155,8 +155,8 @@ func main() {
e.Use(session.Middleware(redisStore))
// Setup caches
userSessionCache = ttlcache.New(ttlcache.WithTTL[string, *SessionData](24 * time.Hour))
webhookTimerCache = ttlcache.New(ttlcache.WithTTL[string, *time.Timer](60 * time.Second))
userSessionCache = ttlcache.New(ttlcache.WithTTL[string, *SessionData](168 * time.Hour))
webhookTimerCache = ttlcache.New(ttlcache.WithTTL[string, *time.Timer](5 * time.Minute))
orphanRooms = ttlcache.New(ttlcache.WithTTL[string, bool](24 * time.Hour))
go userSessionCache.Start()
go webhookTimerCache.Start()

Wyświetl plik

@ -92,7 +92,6 @@ func livekitWebhookHandler(c echo.Context) error {
log.Println(err)
}
nextUser.ClearUserAvatar(ctx)
userSessionCache.Delete(audonID)
} else if err != nil {
log.Println(err)
}