Detach session activity update from statuses (#6379)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
b868aa1dc7
Коммит
0ae6886513
@@ -222,6 +222,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
if c.Err == nil && h.isUserActivity && token != "" && len(c.Session.UserId) > 0 {
|
if c.Err == nil && h.isUserActivity && token != "" && len(c.Session.UserId) > 0 {
|
||||||
app.SetStatusOnline(c.Session.UserId, c.Session.Id, false)
|
app.SetStatusOnline(c.Session.UserId, c.Session.Id, false)
|
||||||
|
app.UpdateLastActivityAtIfNeeded(c.Session)
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.Err == nil && (h.requireUser || h.requireSystemAdmin) {
|
if c.Err == nil && (h.requireUser || h.requireSystemAdmin) {
|
||||||
|
|||||||
@@ -181,3 +181,17 @@ func AttachDeviceId(sessionId string, deviceId string, expiresAt int64) *model.A
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func UpdateLastActivityAtIfNeeded(session model.Session) {
|
||||||
|
now := model.GetMillis()
|
||||||
|
if now-session.LastActivityAt < model.SESSION_ACTIVITY_TIMEOUT {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if result := <-Srv.Store.Session().UpdateLastActivityAt(session.Id, now); result.Err != nil {
|
||||||
|
l4g.Error(utils.T("api.status.last_activity.error", session.UserId, session.Id))
|
||||||
|
}
|
||||||
|
|
||||||
|
session.LastActivityAt = now
|
||||||
|
AddSessionToCache(&session)
|
||||||
|
}
|
||||||
|
|||||||
@@ -195,7 +195,6 @@ func SetStatusOnline(userId string, sessionId string, manual bool) {
|
|||||||
// Only update the database if the status has changed, the status has been manually set,
|
// Only update the database if the status has changed, the status has been manually set,
|
||||||
// or enough time has passed since the previous action
|
// or enough time has passed since the previous action
|
||||||
if status.Status != oldStatus || status.Manual != oldManual || status.LastActivityAt-oldTime > model.STATUS_MIN_UPDATE_TIME {
|
if status.Status != oldStatus || status.Manual != oldManual || status.LastActivityAt-oldTime > model.STATUS_MIN_UPDATE_TIME {
|
||||||
achan := Srv.Store.Session().UpdateLastActivityAt(sessionId, status.LastActivityAt)
|
|
||||||
|
|
||||||
var schan store.StoreChannel
|
var schan store.StoreChannel
|
||||||
if broadcast {
|
if broadcast {
|
||||||
@@ -204,10 +203,6 @@ func SetStatusOnline(userId string, sessionId string, manual bool) {
|
|||||||
schan = Srv.Store.Status().UpdateLastActivityAt(status.UserId, status.LastActivityAt)
|
schan = Srv.Store.Status().UpdateLastActivityAt(status.UserId, status.LastActivityAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := <-achan; result.Err != nil {
|
|
||||||
l4g.Error(utils.T("api.status.last_activity.error"), userId, sessionId, result.Err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if result := <-schan; result.Err != nil {
|
if result := <-schan; result.Err != nil {
|
||||||
l4g.Error(utils.T("api.status.save_status.error"), userId, result.Err)
|
l4g.Error(utils.T("api.status.save_status.error"), userId, result.Err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,10 @@ type WebConn struct {
|
|||||||
|
|
||||||
func NewWebConn(ws *websocket.Conn, session model.Session, t goi18n.TranslateFunc, locale string) *WebConn {
|
func NewWebConn(ws *websocket.Conn, session model.Session, t goi18n.TranslateFunc, locale string) *WebConn {
|
||||||
if len(session.UserId) > 0 {
|
if len(session.UserId) > 0 {
|
||||||
go SetStatusOnline(session.UserId, session.Id, false)
|
go func() {
|
||||||
|
SetStatusOnline(session.UserId, session.Id, false)
|
||||||
|
UpdateLastActivityAtIfNeeded(session)
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
return &WebConn{
|
return &WebConn{
|
||||||
|
|||||||
@@ -53,7 +53,10 @@ func (wr *WebSocketRouter) ServeWebSocket(conn *WebConn, r *model.WebSocketReque
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
conn.WebSocket.Close()
|
conn.WebSocket.Close()
|
||||||
} else {
|
} else {
|
||||||
go SetStatusOnline(session.UserId, session.Id, false)
|
go func() {
|
||||||
|
SetStatusOnline(session.UserId, session.Id, false)
|
||||||
|
UpdateLastActivityAtIfNeeded(*session)
|
||||||
|
}()
|
||||||
|
|
||||||
conn.SessionToken = session.Token
|
conn.SessionToken = session.Token
|
||||||
conn.UserId = session.UserId
|
conn.UserId = session.UserId
|
||||||
|
|||||||
@@ -10,12 +10,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SESSION_COOKIE_TOKEN = "MMAUTHTOKEN"
|
SESSION_COOKIE_TOKEN = "MMAUTHTOKEN"
|
||||||
SESSION_COOKIE_USER = "MMUSERID"
|
SESSION_COOKIE_USER = "MMUSERID"
|
||||||
SESSION_CACHE_SIZE = 35000
|
SESSION_CACHE_SIZE = 35000
|
||||||
SESSION_PROP_PLATFORM = "platform"
|
SESSION_PROP_PLATFORM = "platform"
|
||||||
SESSION_PROP_OS = "os"
|
SESSION_PROP_OS = "os"
|
||||||
SESSION_PROP_BROWSER = "browser"
|
SESSION_PROP_BROWSER = "browser"
|
||||||
|
SESSION_ACTIVITY_TIMEOUT = 1000 * 60 * 5 // 5 minutes
|
||||||
)
|
)
|
||||||
|
|
||||||
type Session struct {
|
type Session struct {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user