MM-15295: Migrate commandstore.AnalyticsCommandCount to sync by default (#10746)
Этот коммит содержится в:
коммит произвёл
George Goldberg
родитель
d59843725f
Коммит
d4225349ef
@@ -193,7 +193,14 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
oHookChan := a.Srv.Store.Webhook().AnalyticsOutgoingCount(teamId)
|
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()
|
sessionChan := a.Srv.Store.Session().AnalyticsSessionCount()
|
||||||
|
|
||||||
var fileChan store.StoreChannel
|
var fileChan store.StoreChannel
|
||||||
|
|||||||
@@ -193,9 +193,7 @@ func (a *App) trackActivity() {
|
|||||||
postsCount = pcr.Data.(int64)
|
postsCount = pcr.Data.(int64)
|
||||||
}
|
}
|
||||||
|
|
||||||
if scc := <-a.Srv.Store.Command().AnalyticsCommandCount(""); scc.Err == nil {
|
slashCommandsCount, _ = a.Srv.Store.Command().AnalyticsCommandCount("")
|
||||||
slashCommandsCount = scc.Data.(int64)
|
|
||||||
}
|
|
||||||
|
|
||||||
if c, err := a.Srv.Store.Webhook().AnalyticsIncomingCount(""); err == nil {
|
if c, err := a.Srv.Store.Webhook().AnalyticsIncomingCount(""); err == nil {
|
||||||
incomingWebhooksCount = c
|
incomingWebhooksCount = c
|
||||||
|
|||||||
@@ -142,24 +142,22 @@ func (s SqlCommandStore) Update(cmd *model.Command) (*model.Command, *model.AppE
|
|||||||
return cmd, nil
|
return cmd, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlCommandStore) AnalyticsCommandCount(teamId string) store.StoreChannel {
|
func (s SqlCommandStore) AnalyticsCommandCount(teamId string) (int64, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
query :=
|
||||||
query :=
|
`SELECT
|
||||||
`SELECT
|
COUNT(*)
|
||||||
COUNT(*)
|
FROM
|
||||||
FROM
|
Commands
|
||||||
Commands
|
WHERE
|
||||||
WHERE
|
DeleteAt = 0`
|
||||||
DeleteAt = 0`
|
|
||||||
|
|
||||||
if len(teamId) > 0 {
|
if len(teamId) > 0 {
|
||||||
query += " AND TeamId = :TeamId"
|
query += " AND TeamId = :TeamId"
|
||||||
}
|
}
|
||||||
|
|
||||||
if c, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId}); err != nil {
|
c, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId})
|
||||||
result.Err = model.NewAppError("SqlCommandStore.AnalyticsCommandCount", "store.sql_command.analytics_command_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
if err != nil {
|
||||||
} else {
|
return 0, model.NewAppError("SqlCommandStore.AnalyticsCommandCount", "store.sql_command.analytics_command_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
result.Data = c
|
}
|
||||||
}
|
return c, nil
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -417,7 +417,7 @@ type CommandStore interface {
|
|||||||
PermanentDeleteByTeam(teamId string) *model.AppError
|
PermanentDeleteByTeam(teamId string) *model.AppError
|
||||||
PermanentDeleteByUser(userId string) *model.AppError
|
PermanentDeleteByUser(userId string) *model.AppError
|
||||||
Update(hook *model.Command) (*model.Command, *model.AppError)
|
Update(hook *model.Command) (*model.Command, *model.AppError)
|
||||||
AnalyticsCommandCount(teamId string) StoreChannel
|
AnalyticsCommandCount(teamId string) (int64, *model.AppError)
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommandWebhookStore interface {
|
type CommandWebhookStore interface {
|
||||||
|
|||||||
@@ -266,18 +266,18 @@ func testCommandCount(t *testing.T, ss store.Store) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if r1 := <-ss.Command().AnalyticsCommandCount(""); r1.Err != nil {
|
if r1, err := ss.Command().AnalyticsCommandCount(""); err != nil {
|
||||||
t.Fatal(r1.Err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
if r1.Data.(int64) == 0 {
|
if r1 == 0 {
|
||||||
t.Fatal("should be at least 1 command")
|
t.Fatal("should be at least 1 command")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if r2 := <-ss.Command().AnalyticsCommandCount(o1.TeamId); r2.Err != nil {
|
if r2, err := ss.Command().AnalyticsCommandCount(o1.TeamId); err != nil {
|
||||||
t.Fatal(r2.Err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
if r2.Data.(int64) != 1 {
|
if r2 != 1 {
|
||||||
t.Fatal("should be 1 command")
|
t.Fatal("should be 1 command")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,19 +14,26 @@ type CommandStore struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AnalyticsCommandCount provides a mock function with given fields: teamId
|
// 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)
|
ret := _m.Called(teamId)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 int64
|
||||||
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string) int64); ok {
|
||||||
r0 = rf(teamId)
|
r0 = rf(teamId)
|
||||||
} 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(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
|
// Delete provides a mock function with given fields: commandId, time
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user