Remove direct Store calls from the Api layer for the file api4/channe… (#15754)
Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
b20dc1828a
Коммит
0e140dad2f
@@ -1736,9 +1736,9 @@ func channelMemberCountsByGroup(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
|
||||
includeTimezones := r.URL.Query().Get("include_timezones") == "true"
|
||||
|
||||
channelMemberCounts, err := c.App.Srv().Store.Channel().GetMemberCountsByGroup(c.Params.ChannelId, includeTimezones)
|
||||
channelMemberCounts, err := c.App.GetMemberCountsByGroup(c.Params.ChannelId, includeTimezones)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.channelMemberCountsByGroup", "app.channel.get_member_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -582,6 +582,7 @@ type AppIface interface {
|
||||
GetLatestTermsOfService() (*model.TermsOfService, *model.AppError)
|
||||
GetLogs(page, perPage int) ([]string, *model.AppError)
|
||||
GetLogsSkipSend(page, perPage int) ([]string, *model.AppError)
|
||||
GetMemberCountsByGroup(channelID string, includeTimezones bool) ([]*model.ChannelMemberCountByGroup, *model.AppError)
|
||||
GetMessageForNotification(post *model.Post, translateFunc i18n.TranslateFunc) string
|
||||
GetMultipleEmojiByName(names []string) ([]*model.Emoji, *model.AppError)
|
||||
GetNewUsersForTeamPage(teamId string, page, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
||||
|
||||
@@ -2854,3 +2854,12 @@ func (a *App) ClearChannelMembersCache(channelID string) {
|
||||
page++
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) GetMemberCountsByGroup(channelID string, includeTimezones bool) ([]*model.ChannelMemberCountByGroup, *model.AppError) {
|
||||
channelMemberCounts, err := a.Srv().Store.Channel().GetMemberCountsByGroup(channelID, includeTimezones)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetMemberCountsByGroup", "app.channel.get_member_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return channelMemberCounts, nil
|
||||
}
|
||||
|
||||
@@ -1898,3 +1898,24 @@ func TestClearChannelMembersCache(t *testing.T) {
|
||||
|
||||
th.App.ClearChannelMembersCache("channelID")
|
||||
}
|
||||
|
||||
func TestGetMemberCountsByGroup(t *testing.T) {
|
||||
th := SetupWithStoreMock(t)
|
||||
defer th.TearDown()
|
||||
|
||||
mockStore := th.App.Srv().Store.(*mocks.Store)
|
||||
mockChannelStore := mocks.ChannelStore{}
|
||||
cmc := []*model.ChannelMemberCountByGroup{}
|
||||
for i := 0; i < 5; i++ {
|
||||
cmc = append(cmc, &model.ChannelMemberCountByGroup{
|
||||
GroupId: model.NewId(),
|
||||
ChannelMemberCount: int64(i),
|
||||
ChannelMemberTimezonesCount: int64(i),
|
||||
})
|
||||
}
|
||||
mockChannelStore.On("GetMemberCountsByGroup", "channelID", true).Return(cmc, nil)
|
||||
mockStore.On("Channel").Return(&mockChannelStore)
|
||||
resp, err := th.App.GetMemberCountsByGroup("channelID", true)
|
||||
require.Nil(t, err)
|
||||
require.ElementsMatch(t, cmc, resp)
|
||||
}
|
||||
|
||||
@@ -6157,6 +6157,28 @@ func (a *OpenTracingAppLayer) GetMarketplacePlugins(filter *model.MarketplacePlu
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetMemberCountsByGroup(channelID string, includeTimezones bool) ([]*model.ChannelMemberCountByGroup, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetMemberCountsByGroup")
|
||||
|
||||
a.ctx = newCtx
|
||||
a.app.Srv().Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
a.app.Srv().Store.SetContext(origCtx)
|
||||
a.ctx = origCtx
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetMemberCountsByGroup(channelID, includeTimezones)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetMessageForNotification(post *model.Post, translateFunc i18n.TranslateFunc) string {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetMessageForNotification")
|
||||
|
||||
Ссылка в новой задаче
Block a user