[MM-15192] Migrate "WebHook.AnalyticsOutgoingCount" to Sync by default (#10711)
Этот коммит содержится в:
коммит произвёл
Hanzei
родитель
2b6573316d
Коммит
b462941f48
@@ -192,7 +192,12 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
||||
close(iHookChan)
|
||||
}()
|
||||
|
||||
oHookChan := a.Srv.Store.Webhook().AnalyticsOutgoingCount(teamId)
|
||||
oHookChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
c, err := a.Srv.Store.Webhook().AnalyticsOutgoingCount(teamId)
|
||||
oHookChan <- store.StoreResult{Data: c, Err: err}
|
||||
close(oHookChan)
|
||||
}()
|
||||
|
||||
commandChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
|
||||
@@ -199,9 +199,7 @@ func (a *App) trackActivity() {
|
||||
incomingWebhooksCount = c
|
||||
}
|
||||
|
||||
if owc := <-a.Srv.Store.Webhook().AnalyticsOutgoingCount(""); owc.Err == nil {
|
||||
outgoingWebhooksCount = owc.Data.(int64)
|
||||
}
|
||||
outgoingWebhooksCount, _ = a.Srv.Store.Webhook().AnalyticsOutgoingCount("")
|
||||
|
||||
a.SendDiagnostic(TRACK_ACTIVITY, map[string]interface{}{
|
||||
"registered_users": userCount,
|
||||
|
||||
@@ -338,24 +338,23 @@ func (s SqlWebhookStore) AnalyticsIncomingCount(teamId string) (int64, *model.Ap
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) AnalyticsOutgoingCount(teamId string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
query :=
|
||||
`SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
OutgoingWebhooks
|
||||
WHERE
|
||||
DeleteAt = 0`
|
||||
func (s SqlWebhookStore) AnalyticsOutgoingCount(teamId string) (int64, *model.AppError) {
|
||||
query :=
|
||||
`SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
OutgoingWebhooks
|
||||
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.AnalyticsOutgoingCount", "store.sql_webhooks.analytics_outgoing_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.AnalyticsOutgoingCount", "store.sql_webhooks.analytics_outgoing_count.app_error", nil, "team_id="+teamId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return v, nil
|
||||
}
|
||||
|
||||
@@ -404,7 +404,7 @@ type WebhookStore interface {
|
||||
UpdateOutgoing(hook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError)
|
||||
|
||||
AnalyticsIncomingCount(teamId string) (int64, *model.AppError)
|
||||
AnalyticsOutgoingCount(teamId string) StoreChannel
|
||||
AnalyticsOutgoingCount(teamId string) (int64, *model.AppError)
|
||||
InvalidateWebhookCache(webhook string)
|
||||
ClearCaches()
|
||||
}
|
||||
|
||||
@@ -37,19 +37,26 @@ func (_m *WebhookStore) AnalyticsIncomingCount(teamId string) (int64, *model.App
|
||||
}
|
||||
|
||||
// AnalyticsOutgoingCount provides a mock function with given fields: teamId
|
||||
func (_m *WebhookStore) AnalyticsOutgoingCount(teamId string) store.StoreChannel {
|
||||
func (_m *WebhookStore) AnalyticsOutgoingCount(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
|
||||
}
|
||||
|
||||
// ClearCaches provides a mock function with given fields:
|
||||
|
||||
@@ -532,10 +532,10 @@ func testWebhookStoreCountOutgoing(t *testing.T, ss store.Store) {
|
||||
|
||||
ss.Webhook().SaveOutgoing(o1)
|
||||
|
||||
if r := <-ss.Webhook().AnalyticsOutgoingCount(""); r.Err != nil {
|
||||
t.Fatal(r.Err)
|
||||
if r, err := ss.Webhook().AnalyticsOutgoingCount(""); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if r.Data.(int64) == 0 {
|
||||
if r == 0 {
|
||||
t.Fatal("should have at least 1 outgoing hook")
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user