mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
MM-15295: Migrate commandstore.AnalyticsCommandCount to sync by default (#10746)
This commit is contained in:
committed by
George Goldberg
parent
d59843725f
commit
d4225349ef
@@ -193,7 +193,14 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
||||
}()
|
||||
|
||||
oHookChan := a.Srv.Store.Webhook().AnalyticsOutgoingCount(teamId)
|
||||
commandChan := a.Srv.Store.Command().AnalyticsCommandCount(teamId)
|
||||
|
||||
commandChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
c, err := a.Srv.Store.Command().AnalyticsCommandCount(teamId)
|
||||
commandChan <- store.StoreResult{Data: c, Err: err}
|
||||
close(commandChan)
|
||||
}()
|
||||
|
||||
sessionChan := a.Srv.Store.Session().AnalyticsSessionCount()
|
||||
|
||||
var fileChan store.StoreChannel
|
||||
|
||||
@@ -193,9 +193,7 @@ func (a *App) trackActivity() {
|
||||
postsCount = pcr.Data.(int64)
|
||||
}
|
||||
|
||||
if scc := <-a.Srv.Store.Command().AnalyticsCommandCount(""); scc.Err == nil {
|
||||
slashCommandsCount = scc.Data.(int64)
|
||||
}
|
||||
slashCommandsCount, _ = a.Srv.Store.Command().AnalyticsCommandCount("")
|
||||
|
||||
if c, err := a.Srv.Store.Webhook().AnalyticsIncomingCount(""); err == nil {
|
||||
incomingWebhooksCount = c
|
||||
|
||||
@@ -142,24 +142,22 @@ func (s SqlCommandStore) Update(cmd *model.Command) (*model.Command, *model.AppE
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func (s SqlCommandStore) AnalyticsCommandCount(teamId string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
query :=
|
||||
`SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
Commands
|
||||
WHERE
|
||||
DeleteAt = 0`
|
||||
func (s SqlCommandStore) AnalyticsCommandCount(teamId string) (int64, *model.AppError) {
|
||||
query :=
|
||||
`SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
Commands
|
||||
WHERE
|
||||
DeleteAt = 0`
|
||||
|
||||
if len(teamId) > 0 {
|
||||
query += " AND TeamId = :TeamId"
|
||||
}
|
||||
if len(teamId) > 0 {
|
||||
query += " AND TeamId = :TeamId"
|
||||
}
|
||||
|
||||
if c, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId}); err != nil {
|
||||
result.Err = model.NewAppError("SqlCommandStore.AnalyticsCommandCount", "store.sql_command.analytics_command_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
} else {
|
||||
result.Data = c
|
||||
}
|
||||
})
|
||||
c, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId})
|
||||
if err != nil {
|
||||
return 0, model.NewAppError("SqlCommandStore.AnalyticsCommandCount", "store.sql_command.analytics_command_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
@@ -417,7 +417,7 @@ type CommandStore interface {
|
||||
PermanentDeleteByTeam(teamId string) *model.AppError
|
||||
PermanentDeleteByUser(userId string) *model.AppError
|
||||
Update(hook *model.Command) (*model.Command, *model.AppError)
|
||||
AnalyticsCommandCount(teamId string) StoreChannel
|
||||
AnalyticsCommandCount(teamId string) (int64, *model.AppError)
|
||||
}
|
||||
|
||||
type CommandWebhookStore interface {
|
||||
|
||||
@@ -266,18 +266,18 @@ func testCommandCount(t *testing.T, ss store.Store) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if r1 := <-ss.Command().AnalyticsCommandCount(""); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
if r1, err := ss.Command().AnalyticsCommandCount(""); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if r1.Data.(int64) == 0 {
|
||||
if r1 == 0 {
|
||||
t.Fatal("should be at least 1 command")
|
||||
}
|
||||
}
|
||||
|
||||
if r2 := <-ss.Command().AnalyticsCommandCount(o1.TeamId); r2.Err != nil {
|
||||
t.Fatal(r2.Err)
|
||||
if r2, err := ss.Command().AnalyticsCommandCount(o1.TeamId); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if r2.Data.(int64) != 1 {
|
||||
if r2 != 1 {
|
||||
t.Fatal("should be 1 command")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,19 +14,26 @@ type CommandStore struct {
|
||||
}
|
||||
|
||||
// AnalyticsCommandCount provides a mock function with given fields: teamId
|
||||
func (_m *CommandStore) AnalyticsCommandCount(teamId string) store.StoreChannel {
|
||||
func (_m *CommandStore) AnalyticsCommandCount(teamId string) (int64, *model.AppError) {
|
||||
ret := _m.Called(teamId)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
|
||||
var r0 int64
|
||||
if rf, ok := ret.Get(0).(func(string) int64); ok {
|
||||
r0 = rf(teamId)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
|
||||
r1 = rf(teamId)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// Delete provides a mock function with given fields: commandId, time
|
||||
|
||||
Reference in New Issue
Block a user