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 удалений

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

@@ -806,11 +806,6 @@ func (s SqlChannelStore) InvalidateChannelByName(teamId, name string) {
}
}
//nolint:unparam
func (s SqlChannelStore) Get(id string, allowFromCache bool) (*model.Channel, error) {
return s.get(id, false)
}
func (s SqlChannelStore) GetPinnedPosts(channelId string) (*model.PostList, error) {
pl := model.NewPostList()
@@ -825,21 +820,10 @@ func (s SqlChannelStore) GetPinnedPosts(channelId string) (*model.PostList, erro
return pl, nil
}
func (s SqlChannelStore) GetFromMaster(id string) (*model.Channel, error) {
return s.get(id, true)
}
func (s SqlChannelStore) get(id string, master bool) (*model.Channel, error) {
var db *sqlxDBWrapper
if master {
db = s.GetMasterX()
} else {
db = s.GetReplicaX()
}
//nolint:unparam
func (s SqlChannelStore) Get(id string, allowFromCache bool) (*model.Channel, error) {
ch := model.Channel{}
err := db.Get(&ch, `SELECT * FROM Channels WHERE Id=?`, id)
err := s.GetReplicaX().Get(&ch, `SELECT * FROM Channels WHERE Id=?`, id)
if err != nil {
if err == sql.ErrNoRows {
return nil, store.NewErrNotFound("Channel", id)
@@ -850,6 +834,30 @@ func (s SqlChannelStore) get(id string, master bool) (*model.Channel, error) {
return &ch, nil
}
//nolint:unparam
func (s SqlChannelStore) GetMany(ids []string, allowFromCache bool) (model.ChannelList, error) {
query := s.getQueryBuilder().
Select("*").
From("Channels").
Where(sq.Eq{"Id": ids})
sql, args, err := query.ToSql()
if err != nil {
return nil, errors.Wrapf(err, "getmany_tosql")
}
channels := model.ChannelList{}
err = s.GetReplicaX().Select(&channels, sql, args...)
if err != nil {
return nil, errors.Wrapf(err, "failed to get channels with ids %v", ids)
}
if len(channels) == 0 {
return nil, store.NewErrNotFound("Channel", fmt.Sprintf("ids=%v", ids))
}
return channels, nil
}
// Delete records the given deleted timestamp to the channel in question.
func (s SqlChannelStore) Delete(channelId string, time int64) error {
return s.SetDeleteAt(channelId, time, time)