[MM-15803] Migrate "Session.AnalyticsSessionCount" to Sync by default (#10948)
* [MM-15803] Migrate "Session.AnalyticsSessionCount" to Sync by default * Use Explict Async for sessionChan in analytics.go
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
ff0d3ab00b
Коммит
674b6f2285
@@ -206,7 +206,12 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||||||
close(commandChan)
|
close(commandChan)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
sessionChan := a.Srv.Store.Session().AnalyticsSessionCount()
|
sessionChan := make(chan store.StoreResult, 1)
|
||||||
|
go func() {
|
||||||
|
count, err := a.Srv.Store.Session().AnalyticsSessionCount()
|
||||||
|
sessionChan <- store.StoreResult{Data: count, Err: err}
|
||||||
|
close(sessionChan)
|
||||||
|
}()
|
||||||
|
|
||||||
var fileChan store.StoreChannel
|
var fileChan store.StoreChannel
|
||||||
var hashtagChan store.StoreChannel
|
var hashtagChan store.StoreChannel
|
||||||
|
|||||||
@@ -206,21 +206,18 @@ func (me SqlSessionStore) UpdateDeviceId(id string, deviceId string, expiresAt i
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (me SqlSessionStore) AnalyticsSessionCount() store.StoreChannel {
|
func (me SqlSessionStore) AnalyticsSessionCount() (int64, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
|
||||||
query :=
|
query :=
|
||||||
`SELECT
|
`SELECT
|
||||||
COUNT(*)
|
COUNT(*)
|
||||||
FROM
|
FROM
|
||||||
Sessions
|
Sessions
|
||||||
WHERE ExpiresAt > :Time`
|
WHERE ExpiresAt > :Time`
|
||||||
|
count, err := me.GetReplica().SelectInt(query, map[string]interface{}{"Time": model.GetMillis()})
|
||||||
if c, err := me.GetReplica().SelectInt(query, map[string]interface{}{"Time": model.GetMillis()}); err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlSessionStore.AnalyticsSessionCount", "store.sql_session.analytics_session_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return int64(0), model.NewAppError("SqlSessionStore.AnalyticsSessionCount", "store.sql_session.analytics_session_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
} else {
|
|
||||||
result.Data = c
|
|
||||||
}
|
}
|
||||||
})
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (me SqlSessionStore) Cleanup(expiryTime int64, batchSize int64) {
|
func (me SqlSessionStore) Cleanup(expiryTime int64, batchSize int64) {
|
||||||
|
|||||||
@@ -322,7 +322,7 @@ type SessionStore interface {
|
|||||||
UpdateLastActivityAt(sessionId string, time int64) StoreChannel
|
UpdateLastActivityAt(sessionId string, time int64) StoreChannel
|
||||||
UpdateRoles(userId string, roles string) StoreChannel
|
UpdateRoles(userId string, roles string) StoreChannel
|
||||||
UpdateDeviceId(id string, deviceId string, expiresAt int64) StoreChannel
|
UpdateDeviceId(id string, deviceId string, expiresAt int64) StoreChannel
|
||||||
AnalyticsSessionCount() StoreChannel
|
AnalyticsSessionCount() (int64, *model.AppError)
|
||||||
Cleanup(expiryTime int64, batchSize int64)
|
Cleanup(expiryTime int64, batchSize int64)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,19 +14,26 @@ type SessionStore struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AnalyticsSessionCount provides a mock function with given fields:
|
// AnalyticsSessionCount provides a mock function with given fields:
|
||||||
func (_m *SessionStore) AnalyticsSessionCount() store.StoreChannel {
|
func (_m *SessionStore) AnalyticsSessionCount() (int64, *model.AppError) {
|
||||||
ret := _m.Called()
|
ret := _m.Called()
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 int64
|
||||||
if rf, ok := ret.Get(0).(func() store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func() int64); ok {
|
||||||
r0 = rf()
|
r0 = rf()
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
r0 = ret.Get(0).(int64)
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
}
|
||||||
|
|
||||||
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func() *model.AppError); ok {
|
||||||
|
r1 = rf()
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup provides a mock function with given fields: expiryTime, batchSize
|
// Cleanup provides a mock function with given fields: expiryTime, batchSize
|
||||||
|
|||||||
@@ -245,10 +245,10 @@ func testSessionCount(t *testing.T, ss store.Store) {
|
|||||||
s1.ExpiresAt = model.GetMillis() + 100000
|
s1.ExpiresAt = model.GetMillis() + 100000
|
||||||
store.Must(ss.Session().Save(&s1))
|
store.Must(ss.Session().Save(&s1))
|
||||||
|
|
||||||
if r1 := <-ss.Session().AnalyticsSessionCount(); r1.Err != nil {
|
if count, err := ss.Session().AnalyticsSessionCount(); err != nil {
|
||||||
t.Fatal(r1.Err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
if r1.Data.(int64) == 0 {
|
if count == 0 {
|
||||||
t.Fatal("should have at least 1 session")
|
t.Fatal("should have at least 1 session")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user