GH-10932 Migrate 'Session.UpdateLastActivityAt' to Sync by default (#11078)
* Migrate Session.UpdateLastActivityAt to Sync by default * GH-10932 fix tests * GH-10932 update add session code
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
cc834e74d4
Коммит
b0ad3c10e9
@@ -223,8 +223,8 @@ func (a *App) UpdateLastActivityAtIfNeeded(session model.Session) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := <-a.Srv.Store.Session().UpdateLastActivityAt(session.Id, now); result.Err != nil {
|
if err := a.Srv.Store.Session().UpdateLastActivityAt(session.Id, now); err != nil {
|
||||||
mlog.Error(fmt.Sprintf("Failed to update LastActivityAt for user_id=%v and session_id=%v, err=%v", session.UserId, session.Id, result.Err), mlog.String("user_id", session.UserId))
|
mlog.Error(fmt.Sprintf("Failed to update LastActivityAt for user_id=%v and session_id=%v, err=%v", session.UserId, session.Id, err), mlog.String("user_id", session.UserId))
|
||||||
}
|
}
|
||||||
|
|
||||||
session.LastActivityAt = now
|
session.LastActivityAt = now
|
||||||
|
|||||||
@@ -56,7 +56,8 @@ func TestGetSessionIdleTimeoutInMinutes(t *testing.T) {
|
|||||||
|
|
||||||
// Test regular session, should timeout
|
// Test regular session, should timeout
|
||||||
time := session.LastActivityAt - (1000 * 60 * 6)
|
time := session.LastActivityAt - (1000 * 60 * 6)
|
||||||
<-th.App.Srv.Store.Session().UpdateLastActivityAt(session.Id, time)
|
err = th.App.Srv.Store.Session().UpdateLastActivityAt(session.Id, time)
|
||||||
|
require.Nil(t, err)
|
||||||
th.App.ClearSessionCacheForUserSkipClusterSend(session.UserId)
|
th.App.ClearSessionCacheForUserSkipClusterSend(session.UserId)
|
||||||
|
|
||||||
rsession, err = th.App.GetSession(session.Token)
|
rsession, err = th.App.GetSession(session.Token)
|
||||||
@@ -73,7 +74,8 @@ func TestGetSessionIdleTimeoutInMinutes(t *testing.T) {
|
|||||||
|
|
||||||
session, _ = th.App.CreateSession(session)
|
session, _ = th.App.CreateSession(session)
|
||||||
time = session.LastActivityAt - (1000 * 60 * 6)
|
time = session.LastActivityAt - (1000 * 60 * 6)
|
||||||
<-th.App.Srv.Store.Session().UpdateLastActivityAt(session.Id, time)
|
err = th.App.Srv.Store.Session().UpdateLastActivityAt(session.Id, time)
|
||||||
|
require.Nil(t, err)
|
||||||
th.App.ClearSessionCacheForUserSkipClusterSend(session.UserId)
|
th.App.ClearSessionCacheForUserSkipClusterSend(session.UserId)
|
||||||
|
|
||||||
_, err = th.App.GetSession(session.Token)
|
_, err = th.App.GetSession(session.Token)
|
||||||
@@ -87,7 +89,8 @@ func TestGetSessionIdleTimeoutInMinutes(t *testing.T) {
|
|||||||
|
|
||||||
session, _ = th.App.CreateSession(session)
|
session, _ = th.App.CreateSession(session)
|
||||||
time = session.LastActivityAt - (1000 * 60 * 6)
|
time = session.LastActivityAt - (1000 * 60 * 6)
|
||||||
<-th.App.Srv.Store.Session().UpdateLastActivityAt(session.Id, time)
|
err = th.App.Srv.Store.Session().UpdateLastActivityAt(session.Id, time)
|
||||||
|
require.Nil(t, err)
|
||||||
th.App.ClearSessionCacheForUserSkipClusterSend(session.UserId)
|
th.App.ClearSessionCacheForUserSkipClusterSend(session.UserId)
|
||||||
|
|
||||||
_, err = th.App.GetSession(session.Token)
|
_, err = th.App.GetSession(session.Token)
|
||||||
@@ -104,7 +107,8 @@ func TestGetSessionIdleTimeoutInMinutes(t *testing.T) {
|
|||||||
|
|
||||||
session, _ = th.App.CreateSession(session)
|
session, _ = th.App.CreateSession(session)
|
||||||
time = session.LastActivityAt - (1000 * 60 * 6)
|
time = session.LastActivityAt - (1000 * 60 * 6)
|
||||||
<-th.App.Srv.Store.Session().UpdateLastActivityAt(session.Id, time)
|
err = th.App.Srv.Store.Session().UpdateLastActivityAt(session.Id, time)
|
||||||
|
require.Nil(t, err)
|
||||||
th.App.ClearSessionCacheForUserSkipClusterSend(session.UserId)
|
th.App.ClearSessionCacheForUserSkipClusterSend(session.UserId)
|
||||||
|
|
||||||
_, err = th.App.GetSession(session.Token)
|
_, err = th.App.GetSession(session.Token)
|
||||||
|
|||||||
@@ -170,14 +170,12 @@ func (me SqlSessionStore) PermanentDeleteSessionsByUser(userId string) *model.Ap
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (me SqlSessionStore) UpdateLastActivityAt(sessionId string, time int64) store.StoreChannel {
|
func (me SqlSessionStore) UpdateLastActivityAt(sessionId string, time int64) *model.AppError {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
_, err := me.GetMaster().Exec("UPDATE Sessions SET LastActivityAt = :LastActivityAt WHERE Id = :Id", map[string]interface{}{"LastActivityAt": time, "Id": sessionId})
|
||||||
if _, err := me.GetMaster().Exec("UPDATE Sessions SET LastActivityAt = :LastActivityAt WHERE Id = :Id", map[string]interface{}{"LastActivityAt": time, "Id": sessionId}); err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlSessionStore.UpdateLastActivityAt", "store.sql_session.update_last_activity.app_error", nil, "sessionId="+sessionId, http.StatusInternalServerError)
|
return model.NewAppError("SqlSessionStore.UpdateLastActivityAt", "store.sql_session.update_last_activity.app_error", nil, "sessionId="+sessionId, http.StatusInternalServerError)
|
||||||
} else {
|
}
|
||||||
result.Data = sessionId
|
return nil
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (me SqlSessionStore) UpdateRoles(userId, roles string) store.StoreChannel {
|
func (me SqlSessionStore) UpdateRoles(userId, roles string) store.StoreChannel {
|
||||||
|
|||||||
@@ -319,7 +319,7 @@ type SessionStore interface {
|
|||||||
Remove(sessionIdOrToken string) StoreChannel
|
Remove(sessionIdOrToken string) StoreChannel
|
||||||
RemoveAllSessions() *model.AppError
|
RemoveAllSessions() *model.AppError
|
||||||
PermanentDeleteSessionsByUser(teamId string) *model.AppError
|
PermanentDeleteSessionsByUser(teamId string) *model.AppError
|
||||||
UpdateLastActivityAt(sessionId string, time int64) StoreChannel
|
UpdateLastActivityAt(sessionId string, time int64) *model.AppError
|
||||||
UpdateRoles(userId string, roles string) StoreChannel
|
UpdateRoles(userId string, roles string) StoreChannel
|
||||||
UpdateDeviceId(id string, deviceId string, expiresAt int64) (string, *model.AppError)
|
UpdateDeviceId(id string, deviceId string, expiresAt int64) (string, *model.AppError)
|
||||||
AnalyticsSessionCount() (int64, *model.AppError)
|
AnalyticsSessionCount() (int64, *model.AppError)
|
||||||
|
|||||||
@@ -213,15 +213,15 @@ func (_m *SessionStore) UpdateDeviceId(id string, deviceId string, expiresAt int
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateLastActivityAt provides a mock function with given fields: sessionId, time
|
// UpdateLastActivityAt provides a mock function with given fields: sessionId, time
|
||||||
func (_m *SessionStore) UpdateLastActivityAt(sessionId string, time int64) store.StoreChannel {
|
func (_m *SessionStore) UpdateLastActivityAt(sessionId string, time int64) *model.AppError {
|
||||||
ret := _m.Called(sessionId, time)
|
ret := _m.Called(sessionId, time)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 *model.AppError
|
||||||
if rf, ok := ret.Get(0).(func(string, int64) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string, int64) *model.AppError); ok {
|
||||||
r0 = rf(sessionId, time)
|
r0 = rf(sessionId, time)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
r0 = ret.Get(0).(*model.AppError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -258,9 +258,8 @@ func testSessionStoreUpdateLastActivityAt(t *testing.T, ss store.Store) {
|
|||||||
s1, err := ss.Session().Save(s1)
|
s1, err := ss.Session().Save(s1)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
if err := (<-ss.Session().UpdateLastActivityAt(s1.Id, 1234567890)).Err; err != nil {
|
err = ss.Session().UpdateLastActivityAt(s1.Id, 1234567890)
|
||||||
t.Fatal(err)
|
require.Nil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
if session, err := ss.Session().Get(s1.Id); err != nil {
|
if session, err := ss.Session().Get(s1.Id); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user