Migrate Channel.AnalyticsTypeCount to Sync by default (#11097)
* Migrate Channel.AnalyticsTypeCount to Sync by default * Fixing tests
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
b13c5eabff
Коммит
7c4cc21475
@@ -1909,22 +1909,18 @@ func (s SqlChannelStore) GetForPost(postId string) store.StoreChannel {
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) AnalyticsTypeCount(teamId string, channelType string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
query := "SELECT COUNT(Id) AS Value FROM Channels WHERE Type = :ChannelType"
|
||||
func (s SqlChannelStore) AnalyticsTypeCount(teamId string, channelType string) (int64, *model.AppError) {
|
||||
query := "SELECT COUNT(Id) AS Value FROM Channels WHERE Type = :ChannelType"
|
||||
|
||||
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.AnalyticsTypeCount", "store.sql_channel.analytics_type_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
result.Data = v
|
||||
})
|
||||
value, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId, "ChannelType": channelType})
|
||||
if err != nil {
|
||||
return int64(0), model.NewAppError("SqlChannelStore.AnalyticsTypeCount", "store.sql_channel.analytics_type_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return value, nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) AnalyticsDeletedTypeCount(teamId string, channelType string) store.StoreChannel {
|
||||
|
||||
@@ -177,7 +177,7 @@ type ChannelStore interface {
|
||||
PermanentDeleteMembersByChannel(channelId string) StoreChannel
|
||||
UpdateLastViewedAt(channelIds []string, userId string) StoreChannel
|
||||
IncrementMentionCount(channelId string, userId string) StoreChannel
|
||||
AnalyticsTypeCount(teamId string, channelType string) StoreChannel
|
||||
AnalyticsTypeCount(teamId string, channelType string) (int64, *model.AppError)
|
||||
GetMembersForUser(teamId string, userId string) StoreChannel
|
||||
GetMembersForUserWithPagination(teamId, userId string, page, perPage int) StoreChannel
|
||||
AutocompleteInTeam(teamId string, term string, includeDeleted bool) StoreChannel
|
||||
|
||||
@@ -1321,15 +1321,15 @@ func testChannelStoreGetMoreChannels(t *testing.T, ss store.Store) {
|
||||
})
|
||||
|
||||
t.Run("verify analytics for open channels", func(t *testing.T) {
|
||||
result := <-ss.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_OPEN)
|
||||
require.Nil(t, result.Err)
|
||||
require.EqualValues(t, 4, result.Data.(int64))
|
||||
count, err := ss.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_OPEN)
|
||||
require.Nil(t, err)
|
||||
require.EqualValues(t, 4, count)
|
||||
})
|
||||
|
||||
t.Run("verify analytics for private channels", func(t *testing.T) {
|
||||
result := <-ss.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_PRIVATE)
|
||||
require.Nil(t, result.Err)
|
||||
require.EqualValues(t, 2, result.Data.(int64))
|
||||
count, err := ss.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_PRIVATE)
|
||||
require.Nil(t, err)
|
||||
require.EqualValues(t, 2, count)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1413,15 +1413,15 @@ func testChannelStoreGetPublicChannelsForTeam(t *testing.T, ss store.Store) {
|
||||
})
|
||||
|
||||
t.Run("verify analytics for open channels", func(t *testing.T) {
|
||||
result := <-ss.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_OPEN)
|
||||
require.Nil(t, result.Err)
|
||||
require.EqualValues(t, 3, result.Data.(int64))
|
||||
count, err := ss.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_OPEN)
|
||||
require.Nil(t, err)
|
||||
require.EqualValues(t, 3, count)
|
||||
})
|
||||
|
||||
t.Run("verify analytics for private channels", func(t *testing.T) {
|
||||
result := <-ss.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_PRIVATE)
|
||||
require.Nil(t, result.Err)
|
||||
require.EqualValues(t, 1, result.Data.(int64))
|
||||
count, err := ss.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_PRIVATE)
|
||||
require.Nil(t, err)
|
||||
require.EqualValues(t, 1, count)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -30,19 +30,26 @@ func (_m *ChannelStore) AnalyticsDeletedTypeCount(teamId string, channelType str
|
||||
}
|
||||
|
||||
// AnalyticsTypeCount provides a mock function with given fields: teamId, channelType
|
||||
func (_m *ChannelStore) AnalyticsTypeCount(teamId string, channelType string) store.StoreChannel {
|
||||
func (_m *ChannelStore) AnalyticsTypeCount(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
|
||||
}
|
||||
|
||||
// AutocompleteInTeam provides a mock function with given fields: teamId, term, includeDeleted
|
||||
|
||||
Ссылка в новой задаче
Block a user