Add channels dataloader

https://mattermost.atlassian.net/browse/MM-43145

```release-note
NONE
```
Этот коммит содержится в:
Agniva De Sarker
2022-04-11 13:41:09 +05:30
коммит произвёл GitHub
родитель 4b354685e9
Коммит d1de4857aa
14 изменённых файлов: 277 добавлений и 90 удалений

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

@@ -569,6 +569,7 @@ type AppIface interface {
GetChannelPinnedPostCount(channelID string) (int64, *model.AppError)
GetChannelPoliciesForUser(userID string, offset, limit int) (*model.RetentionPolicyForChannelList, *model.AppError)
GetChannelUnread(channelID, userID string) (*model.ChannelUnread, *model.AppError)
GetChannels(channelIDs []string) ([]*model.Channel, *model.AppError)
GetChannelsByNames(channelNames []string, teamID string) ([]*model.Channel, *model.AppError)
GetChannelsForRetentionPolicy(policyID string, offset, limit int) (*model.ChannelsWithCount, *model.AppError)
GetChannelsForScheme(scheme *model.Scheme, offset int, limit int) (model.ChannelList, *model.AppError)

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

@@ -1736,6 +1736,20 @@ func (s *Server) getChannel(channelID string) (*model.Channel, *model.AppError)
return channel, nil
}
func (a *App) GetChannels(channelIDs []string) ([]*model.Channel, *model.AppError) {
channels, err := a.Srv().Store.Channel().GetMany(channelIDs, true)
if err != nil {
var nfErr *store.ErrNotFound
switch {
case errors.As(err, &nfErr):
return nil, model.NewAppError("GetChannel", "app.channel.get.existing.app_error", nil, nfErr.Error(), http.StatusNotFound)
default:
return nil, model.NewAppError("GetChannel", "app.channel.get.find.app_error", nil, err.Error(), http.StatusInternalServerError)
}
}
return channels, nil
}
func (a *App) GetChannelByName(channelName, teamID string, includeDeleted bool) (*model.Channel, *model.AppError) {
var channel *model.Channel
var err error

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

@@ -5176,6 +5176,28 @@ func (a *OpenTracingAppLayer) GetChannelUnread(channelID string, userID string)
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) GetChannels(channelIDs []string) ([]*model.Channel, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetChannels")
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.GetChannels(channelIDs)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
ext.Error.Set(span, true)
}
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) GetChannelsByNames(channelNames []string, teamID string) ([]*model.Channel, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetChannelsByNames")