[MM-15191] Migrate Webhook.AnalyticsIncomingCount to Sync (#10674)
* Migrate Webhook.AnalyticsIncomingCount to Sync * update indentation * fix indentation
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
cf5f5be0d8
Коммит
88810a8ec7
@@ -185,7 +185,13 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
||||
rows[4] = &model.AnalyticsRow{Name: "command_count", Value: 0}
|
||||
rows[5] = &model.AnalyticsRow{Name: "session_count", Value: 0}
|
||||
|
||||
iHookChan := a.Srv.Store.Webhook().AnalyticsIncomingCount(teamId)
|
||||
iHookChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
c, err := a.Srv.Store.Webhook().AnalyticsIncomingCount(teamId)
|
||||
iHookChan <- store.StoreResult{Data: c, Err: err}
|
||||
close(iHookChan)
|
||||
}()
|
||||
|
||||
oHookChan := a.Srv.Store.Webhook().AnalyticsOutgoingCount(teamId)
|
||||
commandChan := a.Srv.Store.Command().AnalyticsCommandCount(teamId)
|
||||
sessionChan := a.Srv.Store.Session().AnalyticsSessionCount()
|
||||
|
||||
@@ -197,8 +197,8 @@ func (a *App) trackActivity() {
|
||||
slashCommandsCount = scc.Data.(int64)
|
||||
}
|
||||
|
||||
if iwc := <-a.Srv.Store.Webhook().AnalyticsIncomingCount(""); iwc.Err == nil {
|
||||
incomingWebhooksCount = iwc.Data.(int64)
|
||||
if c, err := a.Srv.Store.Webhook().AnalyticsIncomingCount(""); err == nil {
|
||||
incomingWebhooksCount = c
|
||||
}
|
||||
|
||||
if owc := <-a.Srv.Store.Webhook().AnalyticsOutgoingCount(""); owc.Err == nil {
|
||||
|
||||
@@ -326,26 +326,25 @@ func (s SqlWebhookStore) UpdateOutgoing(hook *model.OutgoingWebhook) store.Store
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) AnalyticsIncomingCount(teamId string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
query :=
|
||||
`SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
IncomingWebhooks
|
||||
WHERE
|
||||
DeleteAt = 0`
|
||||
func (s SqlWebhookStore) AnalyticsIncomingCount(teamId string) (int64, *model.AppError) {
|
||||
query :=
|
||||
`SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
IncomingWebhooks
|
||||
WHERE
|
||||
DeleteAt = 0`
|
||||
|
||||
if len(teamId) > 0 {
|
||||
query += " AND TeamId = :TeamId"
|
||||
}
|
||||
if len(teamId) > 0 {
|
||||
query += " AND TeamId = :TeamId"
|
||||
}
|
||||
|
||||
if v, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId}); err != nil {
|
||||
result.Err = model.NewAppError("SqlWebhookStore.AnalyticsIncomingCount", "store.sql_webhooks.analytics_incoming_count.app_error", nil, "team_id="+teamId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
} else {
|
||||
result.Data = v
|
||||
}
|
||||
})
|
||||
v, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId})
|
||||
if err != nil {
|
||||
return 0, model.NewAppError("SqlWebhookStore.AnalyticsIncomingCount", "store.sql_webhooks.analytics_incoming_count.app_error", nil, "team_id="+teamId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) AnalyticsOutgoingCount(teamId string) store.StoreChannel {
|
||||
|
||||
@@ -397,7 +397,7 @@ type WebhookStore interface {
|
||||
PermanentDeleteOutgoingByUser(userId string) StoreChannel
|
||||
UpdateOutgoing(hook *model.OutgoingWebhook) StoreChannel
|
||||
|
||||
AnalyticsIncomingCount(teamId string) StoreChannel
|
||||
AnalyticsIncomingCount(teamId string) (int64, *model.AppError)
|
||||
AnalyticsOutgoingCount(teamId string) StoreChannel
|
||||
InvalidateWebhookCache(webhook string)
|
||||
ClearCaches()
|
||||
|
||||
@@ -14,19 +14,26 @@ type WebhookStore struct {
|
||||
}
|
||||
|
||||
// AnalyticsIncomingCount provides a mock function with given fields: teamId
|
||||
func (_m *WebhookStore) AnalyticsIncomingCount(teamId string) store.StoreChannel {
|
||||
func (_m *WebhookStore) AnalyticsIncomingCount(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
|
||||
}
|
||||
|
||||
// AnalyticsOutgoingCount provides a mock function with given fields: teamId
|
||||
|
||||
@@ -524,12 +524,13 @@ func testWebhookStoreCountIncoming(t *testing.T, ss store.Store) {
|
||||
|
||||
_, _ = ss.Webhook().SaveIncoming(o1)
|
||||
|
||||
if r := <-ss.Webhook().AnalyticsIncomingCount(""); r.Err != nil {
|
||||
t.Fatal(r.Err)
|
||||
} else {
|
||||
if r.Data.(int64) == 0 {
|
||||
t.Fatal("should have at least 1 incoming hook")
|
||||
}
|
||||
c, err := ss.Webhook().AnalyticsIncomingCount("")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if c == 0 {
|
||||
t.Fatal("should have at least 1 incoming hook")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user