mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[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
This commit is contained in:
@@ -183,12 +183,12 @@ func (a *App) trackActivity() {
|
||||
directChannelCount = dcc
|
||||
}
|
||||
|
||||
if duccr := <-a.Srv.Store.Channel().AnalyticsDeletedTypeCount("", "O"); duccr.Err == nil {
|
||||
deletedPublicChannelCount = duccr.Data.(int64)
|
||||
if duccr, err := a.Srv.Store.Channel().AnalyticsDeletedTypeCount("", "O"); err == nil {
|
||||
deletedPublicChannelCount = duccr
|
||||
}
|
||||
|
||||
if dpccr := <-a.Srv.Store.Channel().AnalyticsDeletedTypeCount("", "P"); dpccr.Err == nil {
|
||||
deletedPrivateChannelCount = dpccr.Data.(int64)
|
||||
if dpccr, err := a.Srv.Store.Channel().AnalyticsDeletedTypeCount("", "P"); err == nil {
|
||||
deletedPrivateChannelCount = dpccr
|
||||
}
|
||||
|
||||
postsCount, _ = a.Srv.Store.Post().AnalyticsPostCount("", false, false)
|
||||
|
||||
@@ -1886,22 +1886,19 @@ func (s SqlChannelStore) AnalyticsTypeCount(teamId string, channelType string) (
|
||||
return value, nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) AnalyticsDeletedTypeCount(teamId string, channelType string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
query := "SELECT COUNT(Id) AS Value FROM Channels WHERE Type = :ChannelType AND DeleteAt > 0"
|
||||
func (s SqlChannelStore) AnalyticsDeletedTypeCount(teamId string, channelType string) (int64, *model.AppError) {
|
||||
query := "SELECT COUNT(Id) AS Value FROM Channels WHERE Type = :ChannelType AND DeleteAt > 0"
|
||||
|
||||
if len(teamId) > 0 {
|
||||
query += " AND TeamId = :TeamId"
|
||||
}
|
||||
if len(teamId) > 0 {
|
||||
query += " AND TeamId = :TeamId"
|
||||
}
|
||||
|
||||
v, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId, "ChannelType": channelType})
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.AnalyticsDeletedTypeCount", "store.sql_channel.analytics_deleted_type_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
v, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId, "ChannelType": channelType})
|
||||
if err != nil {
|
||||
return 0, model.NewAppError("SqlChannelStore.AnalyticsDeletedTypeCount", "store.sql_channel.analytics_deleted_type_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
result.Data = v
|
||||
})
|
||||
return v, nil
|
||||
}
|
||||
|
||||
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)
|
||||
SearchMore(userId string, teamId string, term string) (*model.ChannelList, *model.AppError)
|
||||
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)
|
||||
ClearCaches()
|
||||
GetChannelsByScheme(schemeId string, offset int, limit int) StoreChannel
|
||||
|
||||
@@ -2755,24 +2755,18 @@ func testChannelStoreAnalyticsDeletedTypeCount(t *testing.T, ss store.Store) {
|
||||
}()
|
||||
|
||||
var openStartCount int64
|
||||
if result := <-ss.Channel().AnalyticsDeletedTypeCount("", "O"); result.Err != nil {
|
||||
t.Fatal(result.Err.Error())
|
||||
} else {
|
||||
openStartCount = result.Data.(int64)
|
||||
if openStartCount, err = ss.Channel().AnalyticsDeletedTypeCount("", "O"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var privateStartCount int64
|
||||
if result := <-ss.Channel().AnalyticsDeletedTypeCount("", "P"); result.Err != nil {
|
||||
t.Fatal(result.Err.Error())
|
||||
} else {
|
||||
privateStartCount = result.Data.(int64)
|
||||
if privateStartCount, err = ss.Channel().AnalyticsDeletedTypeCount("", "P"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var directStartCount int64
|
||||
if result := <-ss.Channel().AnalyticsDeletedTypeCount("", "D"); result.Err != nil {
|
||||
t.Fatal(result.Err.Error())
|
||||
} else {
|
||||
directStartCount = result.Data.(int64)
|
||||
if directStartCount, err = ss.Channel().AnalyticsDeletedTypeCount("", "D"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
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())
|
||||
require.Nil(t, err, "channel should have been deleted")
|
||||
|
||||
if result := <-ss.Channel().AnalyticsDeletedTypeCount("", "O"); result.Err != nil {
|
||||
t.Fatal(result.Err.Error())
|
||||
} else {
|
||||
if result.Data.(int64) != openStartCount+2 {
|
||||
t.Fatalf("Wrong open channel deleted count.")
|
||||
}
|
||||
}
|
||||
var count int64
|
||||
|
||||
if result := <-ss.Channel().AnalyticsDeletedTypeCount("", "P"); result.Err != nil {
|
||||
t.Fatal(result.Err.Error())
|
||||
} else {
|
||||
if result.Data.(int64) != privateStartCount+1 {
|
||||
t.Fatalf("Wrong private channel deleted count.")
|
||||
}
|
||||
if count, err = ss.Channel().AnalyticsDeletedTypeCount("", "O"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, openStartCount+2, count, "Wrong open channel deleted count.")
|
||||
|
||||
if result := <-ss.Channel().AnalyticsDeletedTypeCount("", "D"); result.Err != nil {
|
||||
t.Fatal(result.Err.Error())
|
||||
} else {
|
||||
if result.Data.(int64) != directStartCount+1 {
|
||||
t.Fatalf("Wrong direct channel deleted count.")
|
||||
}
|
||||
if count, err = ss.Channel().AnalyticsDeletedTypeCount("", "P"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
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) {
|
||||
|
||||
@@ -14,19 +14,26 @@ type ChannelStore struct {
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string, string) store.StoreChannel); ok {
|
||||
var r0 int64
|
||||
if rf, ok := ret.Get(0).(func(string, string) int64); ok {
|
||||
r0 = rf(teamId, channelType)
|
||||
} 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, 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
|
||||
|
||||
Reference in New Issue
Block a user