[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[4] = &model.AnalyticsRow{Name: "command_count", Value: 0}
|
||||||
rows[5] = &model.AnalyticsRow{Name: "session_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)
|
oHookChan := a.Srv.Store.Webhook().AnalyticsOutgoingCount(teamId)
|
||||||
commandChan := a.Srv.Store.Command().AnalyticsCommandCount(teamId)
|
commandChan := a.Srv.Store.Command().AnalyticsCommandCount(teamId)
|
||||||
sessionChan := a.Srv.Store.Session().AnalyticsSessionCount()
|
sessionChan := a.Srv.Store.Session().AnalyticsSessionCount()
|
||||||
|
|||||||
@@ -197,8 +197,8 @@ func (a *App) trackActivity() {
|
|||||||
slashCommandsCount = scc.Data.(int64)
|
slashCommandsCount = scc.Data.(int64)
|
||||||
}
|
}
|
||||||
|
|
||||||
if iwc := <-a.Srv.Store.Webhook().AnalyticsIncomingCount(""); iwc.Err == nil {
|
if c, err := a.Srv.Store.Webhook().AnalyticsIncomingCount(""); err == nil {
|
||||||
incomingWebhooksCount = iwc.Data.(int64)
|
incomingWebhooksCount = c
|
||||||
}
|
}
|
||||||
|
|
||||||
if owc := <-a.Srv.Store.Webhook().AnalyticsOutgoingCount(""); owc.Err == nil {
|
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 {
|
func (s SqlWebhookStore) AnalyticsIncomingCount(teamId string) (int64, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
query :=
|
||||||
query :=
|
`SELECT
|
||||||
`SELECT
|
COUNT(*)
|
||||||
COUNT(*)
|
FROM
|
||||||
FROM
|
IncomingWebhooks
|
||||||
IncomingWebhooks
|
WHERE
|
||||||
WHERE
|
DeleteAt = 0`
|
||||||
DeleteAt = 0`
|
|
||||||
|
|
||||||
if len(teamId) > 0 {
|
if len(teamId) > 0 {
|
||||||
query += " AND TeamId = :TeamId"
|
query += " AND TeamId = :TeamId"
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId}); err != nil {
|
v, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId})
|
||||||
result.Err = model.NewAppError("SqlWebhookStore.AnalyticsIncomingCount", "store.sql_webhooks.analytics_incoming_count.app_error", nil, "team_id="+teamId+", err="+err.Error(), http.StatusInternalServerError)
|
if err != nil {
|
||||||
} else {
|
return 0, model.NewAppError("SqlWebhookStore.AnalyticsIncomingCount", "store.sql_webhooks.analytics_incoming_count.app_error", nil, "team_id="+teamId+", err="+err.Error(), http.StatusInternalServerError)
|
||||||
result.Data = v
|
}
|
||||||
}
|
|
||||||
})
|
return v, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlWebhookStore) AnalyticsOutgoingCount(teamId string) store.StoreChannel {
|
func (s SqlWebhookStore) AnalyticsOutgoingCount(teamId string) store.StoreChannel {
|
||||||
|
|||||||
@@ -397,7 +397,7 @@ type WebhookStore interface {
|
|||||||
PermanentDeleteOutgoingByUser(userId string) StoreChannel
|
PermanentDeleteOutgoingByUser(userId string) StoreChannel
|
||||||
UpdateOutgoing(hook *model.OutgoingWebhook) StoreChannel
|
UpdateOutgoing(hook *model.OutgoingWebhook) StoreChannel
|
||||||
|
|
||||||
AnalyticsIncomingCount(teamId string) StoreChannel
|
AnalyticsIncomingCount(teamId string) (int64, *model.AppError)
|
||||||
AnalyticsOutgoingCount(teamId string) StoreChannel
|
AnalyticsOutgoingCount(teamId string) StoreChannel
|
||||||
InvalidateWebhookCache(webhook string)
|
InvalidateWebhookCache(webhook string)
|
||||||
ClearCaches()
|
ClearCaches()
|
||||||
|
|||||||
@@ -14,19 +14,26 @@ type WebhookStore struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AnalyticsIncomingCount provides a mock function with given fields: teamId
|
// 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)
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// AnalyticsOutgoingCount provides a mock function with given fields: teamId
|
// 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)
|
_, _ = ss.Webhook().SaveIncoming(o1)
|
||||||
|
|
||||||
if r := <-ss.Webhook().AnalyticsIncomingCount(""); r.Err != nil {
|
c, err := ss.Webhook().AnalyticsIncomingCount("")
|
||||||
t.Fatal(r.Err)
|
if err != nil {
|
||||||
} else {
|
t.Fatal(err)
|
||||||
if r.Data.(int64) == 0 {
|
}
|
||||||
t.Fatal("should have at least 1 incoming hook")
|
|
||||||
}
|
if c == 0 {
|
||||||
|
t.Fatal("should have at least 1 incoming hook")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user