Migrate "User.AnalyticsActiveCount" to Sync by default (#11419)
* migrate User.AnalyticActiveCount to sync default * fixing shadowing variable err * fixing shadowing variable err * run query in async * migrate app/diagnostic to explicit async * remove error logging
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
95652da0b8
Коммит
37b726b651
@@ -66,7 +66,7 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||||||
close(userInactiveChan)
|
close(userInactiveChan)
|
||||||
}()
|
}()
|
||||||
} else {
|
} else {
|
||||||
userChan := make(chan store.StoreResult, 1)
|
userChan = make(chan store.StoreResult, 1)
|
||||||
go func() {
|
go func() {
|
||||||
count, err := a.Srv.Store.User().Count(model.UserCountOptions{TeamId: teamId})
|
count, err := a.Srv.Store.User().Count(model.UserCountOptions{TeamId: teamId})
|
||||||
userChan <- store.StoreResult{Data: count, Err: err}
|
userChan <- store.StoreResult{Data: count, Err: err}
|
||||||
@@ -84,8 +84,6 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
dailyActiveChan := a.Srv.Store.User().AnalyticsActiveCount(DAY_MILLISECONDS)
|
|
||||||
monthlyActiveChan := a.Srv.Store.User().AnalyticsActiveCount(MONTH_MILLISECONDS)
|
|
||||||
teamCountChan := make(chan store.StoreResult, 1)
|
teamCountChan := make(chan store.StoreResult, 1)
|
||||||
go func() {
|
go func() {
|
||||||
teamCount, err := a.Srv.Store.Team().AnalyticsTeamCount()
|
teamCount, err := a.Srv.Store.Team().AnalyticsTeamCount()
|
||||||
@@ -93,6 +91,20 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||||||
close(teamCountChan)
|
close(teamCountChan)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
dailyActiveChan := make(chan store.StoreResult, 1)
|
||||||
|
go func() {
|
||||||
|
dailyActive, err := a.Srv.Store.User().AnalyticsActiveCount(DAY_MILLISECONDS)
|
||||||
|
dailyActiveChan <- store.StoreResult{Data: dailyActive, Err: err}
|
||||||
|
close(dailyActiveChan)
|
||||||
|
}()
|
||||||
|
|
||||||
|
monthlyActiveChan := make(chan store.StoreResult, 1)
|
||||||
|
go func() {
|
||||||
|
monthlyActive, err := a.Srv.Store.User().AnalyticsActiveCount(MONTH_MILLISECONDS)
|
||||||
|
monthlyActiveChan <- store.StoreResult{Data: monthlyActive, Err: err}
|
||||||
|
close(monthlyActiveChan)
|
||||||
|
}()
|
||||||
|
|
||||||
r := <-openChan
|
r := <-openChan
|
||||||
if r.Err != nil {
|
if r.Err != nil {
|
||||||
return nil, r.Err
|
return nil, r.Err
|
||||||
|
|||||||
@@ -8,9 +8,11 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/segmentio/analytics-go"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/mlog"
|
"github.com/mattermost/mattermost-server/mlog"
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
analytics "github.com/segmentio/analytics-go"
|
"github.com/mattermost/mattermost-server/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -124,10 +126,7 @@ func pluginActivated(pluginStates map[string]*model.PluginState, pluginId string
|
|||||||
func (a *App) trackActivity() {
|
func (a *App) trackActivity() {
|
||||||
var userCount int64
|
var userCount int64
|
||||||
var botAccountsCount int64
|
var botAccountsCount int64
|
||||||
var activeUsersDailyCount int64
|
|
||||||
var activeUsersMonthlyCount int64
|
|
||||||
var inactiveUserCount int64
|
var inactiveUserCount int64
|
||||||
var teamCount int64
|
|
||||||
var publicChannelCount int64
|
var publicChannelCount int64
|
||||||
var privateChannelCount int64
|
var privateChannelCount int64
|
||||||
var directChannelCount int64
|
var directChannelCount int64
|
||||||
@@ -140,16 +139,19 @@ func (a *App) trackActivity() {
|
|||||||
var incomingWebhooksCount int64
|
var incomingWebhooksCount int64
|
||||||
var outgoingWebhooksCount int64
|
var outgoingWebhooksCount int64
|
||||||
|
|
||||||
dailyActiveChan := a.Srv.Store.User().AnalyticsActiveCount(DAY_MILLISECONDS)
|
activeUsersDailyCountChan := make(chan store.StoreResult, 1)
|
||||||
monthlyActiveChan := a.Srv.Store.User().AnalyticsActiveCount(MONTH_MILLISECONDS)
|
go func() {
|
||||||
|
count, err := a.Srv.Store.User().AnalyticsActiveCount(DAY_MILLISECONDS)
|
||||||
|
activeUsersDailyCountChan <- store.StoreResult{Data: count, Err: err}
|
||||||
|
close(activeUsersDailyCountChan)
|
||||||
|
}()
|
||||||
|
|
||||||
if r := <-dailyActiveChan; r.Err == nil {
|
activeUsersMonthlyCountChan := make(chan store.StoreResult, 1)
|
||||||
activeUsersDailyCount = r.Data.(int64)
|
go func() {
|
||||||
}
|
count, err := a.Srv.Store.User().AnalyticsActiveCount(MONTH_MILLISECONDS)
|
||||||
|
activeUsersMonthlyCountChan <- store.StoreResult{Data: count, Err: err}
|
||||||
if r := <-monthlyActiveChan; r.Err == nil {
|
close(activeUsersMonthlyCountChan)
|
||||||
activeUsersMonthlyCount = r.Data.(int64)
|
}()
|
||||||
}
|
|
||||||
|
|
||||||
if count, err := a.Srv.Store.User().Count(model.UserCountOptions{IncludeDeleted: true}); err == nil {
|
if count, err := a.Srv.Store.User().Count(model.UserCountOptions{IncludeDeleted: true}); err == nil {
|
||||||
userCount = count
|
userCount = count
|
||||||
@@ -212,6 +214,16 @@ func (a *App) trackActivity() {
|
|||||||
|
|
||||||
outgoingWebhooksCount, _ = a.Srv.Store.Webhook().AnalyticsOutgoingCount("")
|
outgoingWebhooksCount, _ = a.Srv.Store.Webhook().AnalyticsOutgoingCount("")
|
||||||
|
|
||||||
|
var activeUsersDailyCount int64
|
||||||
|
if r := <-activeUsersDailyCountChan; r.Err == nil {
|
||||||
|
activeUsersDailyCount = r.Data.(int64)
|
||||||
|
}
|
||||||
|
|
||||||
|
var activeUsersMonthlyCount int64
|
||||||
|
if r := <-activeUsersMonthlyCountChan; r.Err == nil {
|
||||||
|
activeUsersMonthlyCount = r.Data.(int64)
|
||||||
|
}
|
||||||
|
|
||||||
a.SendDiagnostic(TRACK_ACTIVITY, map[string]interface{}{
|
a.SendDiagnostic(TRACK_ACTIVITY, map[string]interface{}{
|
||||||
"registered_users": userCount,
|
"registered_users": userCount,
|
||||||
"bot_accounts": botAccountsCount,
|
"bot_accounts": botAccountsCount,
|
||||||
|
|||||||
@@ -1171,19 +1171,17 @@ func (us SqlUserStore) Count(options model.UserCountOptions) (int64, *model.AppE
|
|||||||
return count, nil
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) AnalyticsActiveCount(timePeriod int64) store.StoreChannel {
|
func (us SqlUserStore) AnalyticsActiveCount(timePeriod int64) (int64, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
|
||||||
time := model.GetMillis() - timePeriod
|
|
||||||
|
|
||||||
query := "SELECT COUNT(*) FROM Status WHERE LastActivityAt > :Time"
|
time := model.GetMillis() - timePeriod
|
||||||
|
|
||||||
v, err := us.GetReplica().SelectInt(query, map[string]interface{}{"Time": time})
|
query := "SELECT COUNT(*) FROM Status WHERE LastActivityAt > :Time"
|
||||||
if err != nil {
|
|
||||||
result.Err = model.NewAppError("SqlUserStore.AnalyticsDailyActiveUsers", "store.sql_user.analytics_daily_active_users.app_error", nil, err.Error(), http.StatusInternalServerError)
|
v, err := us.GetReplica().SelectInt(query, map[string]interface{}{"Time": time})
|
||||||
} else {
|
if err != nil {
|
||||||
result.Data = v
|
return 0, model.NewAppError("SqlUserStore.AnalyticsDailyActiveUsers", "store.sql_user.analytics_daily_active_users.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
})
|
return v, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) GetUnreadCount(userId string) (int64, error) {
|
func (us SqlUserStore) GetUnreadCount(userId string) (int64, error) {
|
||||||
|
|||||||
@@ -282,7 +282,7 @@ type UserStore interface {
|
|||||||
UpdateFailedPasswordAttempts(userId string, attempts int) StoreChannel
|
UpdateFailedPasswordAttempts(userId string, attempts int) StoreChannel
|
||||||
GetSystemAdminProfiles() (map[string]*model.User, *model.AppError)
|
GetSystemAdminProfiles() (map[string]*model.User, *model.AppError)
|
||||||
PermanentDelete(userId string) *model.AppError
|
PermanentDelete(userId string) *model.AppError
|
||||||
AnalyticsActiveCount(time int64) StoreChannel
|
AnalyticsActiveCount(time int64) (int64, *model.AppError)
|
||||||
GetUnreadCount(userId string) (int64, error)
|
GetUnreadCount(userId string) (int64, error)
|
||||||
GetUnreadCountForChannel(userId string, channelId string) StoreChannel
|
GetUnreadCountForChannel(userId string, channelId string) StoreChannel
|
||||||
GetAnyUnreadPostCountForChannel(userId string, channelId string) (int64, *model.AppError)
|
GetAnyUnreadPostCountForChannel(userId string, channelId string) (int64, *model.AppError)
|
||||||
|
|||||||
@@ -14,19 +14,26 @@ type UserStore struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AnalyticsActiveCount provides a mock function with given fields: time
|
// AnalyticsActiveCount provides a mock function with given fields: time
|
||||||
func (_m *UserStore) AnalyticsActiveCount(time int64) store.StoreChannel {
|
func (_m *UserStore) AnalyticsActiveCount(time int64) (int64, *model.AppError) {
|
||||||
ret := _m.Called(time)
|
ret := _m.Called(time)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 int64
|
||||||
if rf, ok := ret.Get(0).(func(int64) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(int64) int64); ok {
|
||||||
r0 = rf(time)
|
r0 = rf(time)
|
||||||
} 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(int64) *model.AppError); ok {
|
||||||
|
r1 = rf(time)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// AnalyticsGetInactiveUsersCount provides a mock function with given fields:
|
// AnalyticsGetInactiveUsersCount provides a mock function with given fields:
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user