[MM-16353] Migrate Channel.AnalyticsDeletedTypeCount to Sync by default (#11289)

* [MM-16353] Migrate AnalyticsDeletedTypeCount to Sync by default

* refactor: decrease branching

* test: use testify for assertion
Этот коммит содержится в:
krjn
2019-06-19 15:23:16 +00:00
коммит произвёл Jesús Espino
родитель 73a1bb80f1
Коммит a39ceadd58
5 изменённых файлов: 46 добавлений и 55 удалений

Просмотреть файл

@@ -183,12 +183,12 @@ func (a *App) trackActivity() {
directChannelCount = dcc directChannelCount = dcc
} }
if duccr := <-a.Srv.Store.Channel().AnalyticsDeletedTypeCount("", "O"); duccr.Err == nil { if duccr, err := a.Srv.Store.Channel().AnalyticsDeletedTypeCount("", "O"); err == nil {
deletedPublicChannelCount = duccr.Data.(int64) deletedPublicChannelCount = duccr
} }
if dpccr := <-a.Srv.Store.Channel().AnalyticsDeletedTypeCount("", "P"); dpccr.Err == nil { if dpccr, err := a.Srv.Store.Channel().AnalyticsDeletedTypeCount("", "P"); err == nil {
deletedPrivateChannelCount = dpccr.Data.(int64) deletedPrivateChannelCount = dpccr
} }
postsCount, _ = a.Srv.Store.Post().AnalyticsPostCount("", false, false) postsCount, _ = a.Srv.Store.Post().AnalyticsPostCount("", false, false)

Просмотреть файл

@@ -1886,8 +1886,7 @@ func (s SqlChannelStore) AnalyticsTypeCount(teamId string, channelType string) (
return value, nil return value, nil
} }
func (s SqlChannelStore) AnalyticsDeletedTypeCount(teamId string, channelType string) store.StoreChannel { func (s SqlChannelStore) AnalyticsDeletedTypeCount(teamId string, channelType string) (int64, *model.AppError) {
return store.Do(func(result *store.StoreResult) {
query := "SELECT COUNT(Id) AS Value FROM Channels WHERE Type = :ChannelType AND DeleteAt > 0" query := "SELECT COUNT(Id) AS Value FROM Channels WHERE Type = :ChannelType AND DeleteAt > 0"
if len(teamId) > 0 { if len(teamId) > 0 {
@@ -1896,12 +1895,10 @@ func (s SqlChannelStore) AnalyticsDeletedTypeCount(teamId string, channelType st
v, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId, "ChannelType": channelType}) v, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId, "ChannelType": channelType})
if err != nil { if err != nil {
result.Err = model.NewAppError("SqlChannelStore.AnalyticsDeletedTypeCount", "store.sql_channel.analytics_deleted_type_count.app_error", nil, err.Error(), http.StatusInternalServerError) return 0, model.NewAppError("SqlChannelStore.AnalyticsDeletedTypeCount", "store.sql_channel.analytics_deleted_type_count.app_error", nil, err.Error(), http.StatusInternalServerError)
return
} }
result.Data = v return v, nil
})
} }
func (s SqlChannelStore) GetMembersForUser(teamId string, userId string) store.StoreChannel { func (s SqlChannelStore) GetMembersForUser(teamId string, userId string) store.StoreChannel {

Просмотреть файл

@@ -186,7 +186,7 @@ type ChannelStore interface {
SearchInTeam(teamId string, term string, includeDeleted bool) (*model.ChannelList, *model.AppError) SearchInTeam(teamId string, term string, includeDeleted bool) (*model.ChannelList, *model.AppError)
SearchMore(userId string, teamId string, term string) (*model.ChannelList, *model.AppError) SearchMore(userId string, teamId string, term string) (*model.ChannelList, *model.AppError)
GetMembersByIds(channelId string, userIds []string) StoreChannel GetMembersByIds(channelId string, userIds []string) StoreChannel
AnalyticsDeletedTypeCount(teamId string, channelType string) StoreChannel AnalyticsDeletedTypeCount(teamId string, channelType string) (int64, *model.AppError)
GetChannelUnread(channelId, userId string) (*model.ChannelUnread, *model.AppError) GetChannelUnread(channelId, userId string) (*model.ChannelUnread, *model.AppError)
ClearCaches() ClearCaches()
GetChannelsByScheme(schemeId string, offset int, limit int) StoreChannel GetChannelsByScheme(schemeId string, offset int, limit int) StoreChannel

Просмотреть файл

@@ -2755,24 +2755,18 @@ func testChannelStoreAnalyticsDeletedTypeCount(t *testing.T, ss store.Store) {
}() }()
var openStartCount int64 var openStartCount int64
if result := <-ss.Channel().AnalyticsDeletedTypeCount("", "O"); result.Err != nil { if openStartCount, err = ss.Channel().AnalyticsDeletedTypeCount("", "O"); err != nil {
t.Fatal(result.Err.Error()) t.Fatal(err)
} else {
openStartCount = result.Data.(int64)
} }
var privateStartCount int64 var privateStartCount int64
if result := <-ss.Channel().AnalyticsDeletedTypeCount("", "P"); result.Err != nil { if privateStartCount, err = ss.Channel().AnalyticsDeletedTypeCount("", "P"); err != nil {
t.Fatal(result.Err.Error()) t.Fatal(err)
} else {
privateStartCount = result.Data.(int64)
} }
var directStartCount int64 var directStartCount int64
if result := <-ss.Channel().AnalyticsDeletedTypeCount("", "D"); result.Err != nil { if directStartCount, err = ss.Channel().AnalyticsDeletedTypeCount("", "D"); err != nil {
t.Fatal(result.Err.Error()) t.Fatal(err)
} else {
directStartCount = result.Data.(int64)
} }
err = ss.Channel().Delete(o1.Id, model.GetMillis()) err = ss.Channel().Delete(o1.Id, model.GetMillis())
@@ -2784,29 +2778,22 @@ func testChannelStoreAnalyticsDeletedTypeCount(t *testing.T, ss store.Store) {
err = ss.Channel().Delete(d4.Id, model.GetMillis()) err = ss.Channel().Delete(d4.Id, model.GetMillis())
require.Nil(t, err, "channel should have been deleted") require.Nil(t, err, "channel should have been deleted")
if result := <-ss.Channel().AnalyticsDeletedTypeCount("", "O"); result.Err != nil { var count int64
t.Fatal(result.Err.Error())
} else {
if result.Data.(int64) != openStartCount+2 {
t.Fatalf("Wrong open channel deleted count.")
}
}
if result := <-ss.Channel().AnalyticsDeletedTypeCount("", "P"); result.Err != nil { if count, err = ss.Channel().AnalyticsDeletedTypeCount("", "O"); err != nil {
t.Fatal(result.Err.Error()) t.Fatal(err)
} else {
if result.Data.(int64) != privateStartCount+1 {
t.Fatalf("Wrong private channel deleted count.")
}
} }
assert.Equal(t, openStartCount+2, count, "Wrong open channel deleted count.")
if result := <-ss.Channel().AnalyticsDeletedTypeCount("", "D"); result.Err != nil { if count, err = ss.Channel().AnalyticsDeletedTypeCount("", "P"); err != nil {
t.Fatal(result.Err.Error()) t.Fatal(err)
} else {
if result.Data.(int64) != directStartCount+1 {
t.Fatalf("Wrong direct channel deleted count.")
} }
assert.Equal(t, privateStartCount+1, count, "Wrong private channel deleted count.")
if count, err = ss.Channel().AnalyticsDeletedTypeCount("", "D"); err != nil {
t.Fatal(err)
} }
assert.Equal(t, directStartCount+1, count, "Wrong direct channel deleted count.")
} }
func testChannelStoreGetPinnedPosts(t *testing.T, ss store.Store) { func testChannelStoreGetPinnedPosts(t *testing.T, ss store.Store) {

Просмотреть файл

@@ -14,19 +14,26 @@ type ChannelStore struct {
} }
// AnalyticsDeletedTypeCount provides a mock function with given fields: teamId, channelType // AnalyticsDeletedTypeCount provides a mock function with given fields: teamId, channelType
func (_m *ChannelStore) AnalyticsDeletedTypeCount(teamId string, channelType string) store.StoreChannel { func (_m *ChannelStore) AnalyticsDeletedTypeCount(teamId string, channelType string) (int64, *model.AppError) {
ret := _m.Called(teamId, channelType) ret := _m.Called(teamId, channelType)
var r0 store.StoreChannel var r0 int64
if rf, ok := ret.Get(0).(func(string, string) store.StoreChannel); ok { if rf, ok := ret.Get(0).(func(string, string) int64); ok {
r0 = rf(teamId, channelType) r0 = rf(teamId, channelType)
} 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, string) *model.AppError); ok {
r1 = rf(teamId, channelType)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
} }
} }
return r0 return r0, r1
} }
// AnalyticsTypeCount provides a mock function with given fields: teamId, channelType // AnalyticsTypeCount provides a mock function with given fields: teamId, channelType