Migration of ChannelStore Part 1 (#15235)

* Lint: remove unnecessary use of sprintf

* Fix i18n

* Returning the right error (InternalServerError)

* Doing some suggestions

* Fix store layers

* Fix missed translation

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Rodrigo Villablanca
2020-09-03 01:54:46 -04:00
коммит произвёл GitHub
родитель f2a8e10216
Коммит 2cb655ed67
15 изменённых файлов: 361 добавлений и 195 удалений

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

@@ -577,7 +577,7 @@ func (s *OpenTracingLayerChannelStore) ClearCaches() {
}
func (s *OpenTracingLayerChannelStore) ClearSidebarOnTeamLeave(userId string, teamId string) *model.AppError {
func (s *OpenTracingLayerChannelStore) ClearSidebarOnTeamLeave(userId string, teamId string) error {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.ClearSidebarOnTeamLeave")
s.Root.Store.SetContext(newCtx)
@@ -739,7 +739,7 @@ func (s *OpenTracingLayerChannelStore) Get(id string, allowFromCache bool) (*mod
return result, err
}
func (s *OpenTracingLayerChannelStore) GetAll(teamId string) ([]*model.Channel, *model.AppError) {
func (s *OpenTracingLayerChannelStore) GetAll(teamId string) ([]*model.Channel, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetAll")
s.Root.Store.SetContext(newCtx)
@@ -919,7 +919,7 @@ func (s *OpenTracingLayerChannelStore) GetByNames(team_id string, names []string
return result, err
}
func (s *OpenTracingLayerChannelStore) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError) {
func (s *OpenTracingLayerChannelStore) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetChannelCounts")
s.Root.Store.SetContext(newCtx)
@@ -1027,7 +1027,7 @@ func (s *OpenTracingLayerChannelStore) GetChannelsBatchForIndexing(startTime int
return result, err
}
func (s *OpenTracingLayerChannelStore) GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, *model.AppError) {
func (s *OpenTracingLayerChannelStore) GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetChannelsByIds")
s.Root.Store.SetContext(newCtx)
@@ -1099,7 +1099,7 @@ func (s *OpenTracingLayerChannelStore) GetDeletedByName(team_id string, name str
return result, err
}
func (s *OpenTracingLayerChannelStore) GetForPost(postId string) (*model.Channel, *model.AppError) {
func (s *OpenTracingLayerChannelStore) GetForPost(postId string) (*model.Channel, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetForPost")
s.Root.Store.SetContext(newCtx)
@@ -1364,7 +1364,7 @@ func (s *OpenTracingLayerChannelStore) GetPinnedPosts(channelId string) (*model.
return result, err
}
func (s *OpenTracingLayerChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
func (s *OpenTracingLayerChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetPrivateChannelsForTeam")
s.Root.Store.SetContext(newCtx)
@@ -1382,7 +1382,7 @@ func (s *OpenTracingLayerChannelStore) GetPrivateChannelsForTeam(teamId string,
return result, err
}
func (s *OpenTracingLayerChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) {
func (s *OpenTracingLayerChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetPublicChannelsByIdsForTeam")
s.Root.Store.SetContext(newCtx)
@@ -1400,7 +1400,7 @@ func (s *OpenTracingLayerChannelStore) GetPublicChannelsByIdsForTeam(teamId stri
return result, err
}
func (s *OpenTracingLayerChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
func (s *OpenTracingLayerChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetPublicChannelsForTeam")
s.Root.Store.SetContext(newCtx)
@@ -1472,7 +1472,7 @@ func (s *OpenTracingLayerChannelStore) GetSidebarCategoryOrder(userId string, te
return result, err
}
func (s *OpenTracingLayerChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, *model.AppError) {
func (s *OpenTracingLayerChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetTeamChannels")
s.Root.Store.SetContext(newCtx)
@@ -2170,7 +2170,7 @@ func (s *OpenTracingLayerChannelStore) UpdateSidebarCategoryOrder(userId string,
return err
}
func (s *OpenTracingLayerChannelStore) UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) *model.AppError {
func (s *OpenTracingLayerChannelStore) UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) error {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.UpdateSidebarChannelCategoryOnMove")
s.Root.Store.SetContext(newCtx)

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

@@ -544,9 +544,23 @@ func (s *RetryLayerChannelStore) ClearCaches() {
}
func (s *RetryLayerChannelStore) ClearSidebarOnTeamLeave(userId string, teamId string) *model.AppError {
func (s *RetryLayerChannelStore) ClearSidebarOnTeamLeave(userId string, teamId string) error {
return s.ChannelStore.ClearSidebarOnTeamLeave(userId, teamId)
tries := 0
for {
err := s.ChannelStore.ClearSidebarOnTeamLeave(userId, teamId)
if err == nil {
return nil
}
if !isRepeatableError(err) {
return err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return err
}
}
}
@@ -668,9 +682,23 @@ func (s *RetryLayerChannelStore) Get(id string, allowFromCache bool) (*model.Cha
}
func (s *RetryLayerChannelStore) GetAll(teamId string) ([]*model.Channel, *model.AppError) {
func (s *RetryLayerChannelStore) GetAll(teamId string) ([]*model.Channel, error) {
return s.ChannelStore.GetAll(teamId)
tries := 0
for {
result, err := s.ChannelStore.GetAll(teamId)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
}
@@ -798,9 +826,23 @@ func (s *RetryLayerChannelStore) GetByNames(team_id string, names []string, allo
}
func (s *RetryLayerChannelStore) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError) {
func (s *RetryLayerChannelStore) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, error) {
return s.ChannelStore.GetChannelCounts(teamId, userId)
tries := 0
for {
result, err := s.ChannelStore.GetChannelCounts(teamId, userId)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
}
@@ -848,9 +890,23 @@ func (s *RetryLayerChannelStore) GetChannelsBatchForIndexing(startTime int64, en
}
func (s *RetryLayerChannelStore) GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, *model.AppError) {
func (s *RetryLayerChannelStore) GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, error) {
return s.ChannelStore.GetChannelsByIds(channelIds, includeDeleted)
tries := 0
for {
result, err := s.ChannelStore.GetChannelsByIds(channelIds, includeDeleted)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
}
@@ -900,9 +956,23 @@ func (s *RetryLayerChannelStore) GetDeletedByName(team_id string, name string) (
}
func (s *RetryLayerChannelStore) GetForPost(postId string) (*model.Channel, *model.AppError) {
func (s *RetryLayerChannelStore) GetForPost(postId string) (*model.Channel, error) {
return s.ChannelStore.GetForPost(postId)
tries := 0
for {
result, err := s.ChannelStore.GetForPost(postId)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
}
@@ -1018,21 +1088,63 @@ func (s *RetryLayerChannelStore) GetPinnedPosts(channelId string) (*model.PostLi
}
func (s *RetryLayerChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
func (s *RetryLayerChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, error) {
return s.ChannelStore.GetPrivateChannelsForTeam(teamId, offset, limit)
tries := 0
for {
result, err := s.ChannelStore.GetPrivateChannelsForTeam(teamId, offset, limit)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
}
func (s *RetryLayerChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) {
func (s *RetryLayerChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, error) {
return s.ChannelStore.GetPublicChannelsByIdsForTeam(teamId, channelIds)
tries := 0
for {
result, err := s.ChannelStore.GetPublicChannelsByIdsForTeam(teamId, channelIds)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
}
func (s *RetryLayerChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
func (s *RetryLayerChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, error) {
return s.ChannelStore.GetPublicChannelsForTeam(teamId, offset, limit)
tries := 0
for {
result, err := s.ChannelStore.GetPublicChannelsForTeam(teamId, offset, limit)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
}
@@ -1054,9 +1166,23 @@ func (s *RetryLayerChannelStore) GetSidebarCategoryOrder(userId string, teamId s
}
func (s *RetryLayerChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, *model.AppError) {
func (s *RetryLayerChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, error) {
return s.ChannelStore.GetTeamChannels(teamId)
tries := 0
for {
result, err := s.ChannelStore.GetTeamChannels(teamId)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
}
@@ -1412,9 +1538,23 @@ func (s *RetryLayerChannelStore) UpdateSidebarCategoryOrder(userId string, teamI
}
func (s *RetryLayerChannelStore) UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) *model.AppError {
func (s *RetryLayerChannelStore) UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) error {
return s.ChannelStore.UpdateSidebarChannelCategoryOnMove(channel, newTeamId)
tries := 0
for {
err := s.ChannelStore.UpdateSidebarChannelCategoryOnMove(channel, newTeamId)
if err == nil {
return nil
}
if !isRepeatableError(err) {
return err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return err
}
}
}

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

@@ -4,6 +4,8 @@
package searchlayer
import (
"net/http"
"github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/services/searchengine"
@@ -164,8 +166,9 @@ func (c *SearchChannelStore) searchAutocompleteChannels(engine searchengine.Sear
if len(channelIds) > 0 {
channels, err := c.ChannelStore.GetChannelsByIds(channelIds, includeDeleted)
if err != nil {
return nil, err
return nil, model.NewAppError("searchAutocompleteChannels", "app.channel.get_channels_by_ids.app_error", nil, err.Error(), http.StatusInternalServerError)
}
for _, ch := range channels {
channelList = append(channelList, ch)
}

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

@@ -4,6 +4,8 @@
package searchlayer
import (
"errors"
"net/http"
"strings"
"github.com/mattermost/mattermost-server/v5/mlog"
@@ -166,7 +168,13 @@ func (s *SearchUserStore) getListOfAllowedChannelsForTeam(teamId string, viewRes
if teamId != "" && (viewRestrictions == nil || strings.Contains(strings.Join(viewRestrictions.Teams, "."), teamId)) {
channels, err := s.rootStore.Channel().GetTeamChannels(teamId)
if err != nil {
return nil, err
var nfErr *store.ErrNotFound
switch {
case errors.As(err, &nfErr):
return nil, model.NewAppError("getListOfAllowedChannelsForTeam", "app.channel.get_channels.not_found.app_error", nil, nfErr.Error(), http.StatusNotFound)
default:
return nil, model.NewAppError("getListOfAllowedChannelsForTeam", "app.channel.get_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError)
}
}
for _, channel := range *channels {
listOfAllowedChannels = append(listOfAllowedChannels, channel.Id)
@@ -177,7 +185,7 @@ func (s *SearchUserStore) getListOfAllowedChannelsForTeam(teamId string, viewRes
if len(viewRestrictions.Channels) > 0 {
channels, err := s.rootStore.Channel().GetChannelsByIds(viewRestrictions.Channels, false)
if err != nil {
return nil, err
return nil, model.NewAppError("getListOfAllowedChannelsForTeam", "app.channel.get_channels_by_ids.app_error", nil, err.Error(), http.StatusInternalServerError)
}
for _, c := range channels {
if teamId == "" || (teamId != "" && c.TeamId == teamId) {

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

@@ -1085,10 +1085,10 @@ func (s SqlChannelStore) GetMoreChannels(teamId string, userId string, offset in
return channels, nil
}
func (s SqlChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
func (s SqlChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, error) {
channels := &model.ChannelList{}
query := s.getQueryBuilder().
builder := s.getQueryBuilder().
Select("*").
From("Channels").
Where(sq.Eq{"Type": model.CHANNEL_PRIVATE, "TeamId": teamId, "DeleteAt": 0}).
@@ -1096,19 +1096,19 @@ func (s SqlChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, li
Limit(uint64(limit)).
Offset(uint64(offset))
sql, args, err := query.ToSql()
query, args, err := builder.ToSql()
if err != nil {
return nil, model.NewAppError("SqlChannelStore.GetPrivateChannelsForTeam", "store.sql_channel.get_private_channels.get.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError)
return nil, errors.Wrap(err, "channels_tosql")
}
_, err = s.GetReplica().Select(channels, sql, args...)
_, err = s.GetReplica().Select(channels, query, args...)
if err != nil {
return nil, model.NewAppError("SqlChannelStore.GetPrivateChannelsForTeam", "store.sql_channel.get_private_channels.get.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError)
return nil, errors.Wrapf(err, "failed to find chaneld with teamId=%s", teamId)
}
return channels, nil
}
func (s SqlChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
func (s SqlChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, error) {
channels := &model.ChannelList{}
_, err := s.GetReplica().Select(channels, `
SELECT
@@ -1130,13 +1130,13 @@ func (s SqlChannelStore) GetPublicChannelsForTeam(teamId string, offset int, lim
})
if err != nil {
return nil, model.NewAppError("SqlChannelStore.GetPublicChannelsForTeam", "store.sql_channel.get_public_channels.get.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError)
return nil, errors.Wrapf(err, "failed to find chaneld with teamId=%s", teamId)
}
return channels, nil
}
func (s SqlChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) {
func (s SqlChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, error) {
props := make(map[string]interface{})
props["teamId"] = teamId
@@ -1167,11 +1167,11 @@ func (s SqlChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds
`, props)
if err != nil {
return nil, model.NewAppError("SqlChannelStore.GetPublicChannelsByIdsForTeam", "store.sql_channel.get_channels_by_ids.get.app_error", nil, err.Error(), http.StatusInternalServerError)
return nil, errors.Wrap(err, "failed to find Channels")
}
if len(*data) == 0 {
return nil, model.NewAppError("SqlChannelStore.GetPublicChannelsByIdsForTeam", "store.sql_channel.get_channels_by_ids.not_found.app_error", nil, "", http.StatusNotFound)
return nil, store.NewErrNotFound("Channel", fmt.Sprintf("teamId=%s, channelIds=%v", teamId, channelIds))
}
return data, nil
@@ -1183,12 +1183,12 @@ type channelIdWithCountAndUpdateAt struct {
UpdateAt int64
}
func (s SqlChannelStore) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError) {
func (s SqlChannelStore) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, error) {
var data []channelIdWithCountAndUpdateAt
_, err := s.GetReplica().Select(&data, "SELECT Id, TotalMsgCount, UpdateAt FROM Channels WHERE Id IN (SELECT ChannelId FROM ChannelMembers WHERE UserId = :UserId) AND (TeamId = :TeamId OR TeamId = '') AND DeleteAt = 0 ORDER BY DisplayName", map[string]interface{}{"TeamId": teamId, "UserId": userId})
if err != nil {
return nil, model.NewAppError("SqlChannelStore.GetChannelCounts", "store.sql_channel.get_channel_counts.get.app_error", nil, "teamId="+teamId+", userId="+userId+", err="+err.Error(), http.StatusInternalServerError)
return nil, errors.Wrapf(err, "failed to get channels count with teamId=%s and userId=%s", teamId, userId)
}
counts := &model.ChannelCounts{Counts: make(map[string]int64), UpdateTimes: make(map[string]int64)}
@@ -1201,18 +1201,16 @@ func (s SqlChannelStore) GetChannelCounts(teamId string, userId string) (*model.
return counts, nil
}
func (s SqlChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, *model.AppError) {
func (s SqlChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, error) {
data := &model.ChannelList{}
_, err := s.GetReplica().Select(data, "SELECT * FROM Channels WHERE TeamId = :TeamId And Type != 'D' ORDER BY DisplayName", map[string]interface{}{"TeamId": teamId})
if err != nil {
// TODO: This error key would go away once this store method is migrated to return plain errors
return nil, model.NewAppError("SqlChannelStore.GetTeamChannels", "app.channel.get_channels.get.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError)
return nil, errors.Wrapf(err, "failed to find Channels with teamId=%s", teamId)
}
if len(*data) == 0 {
// TODO: This error key would go away once this store method is migrated to return plain errors
return nil, model.NewAppError("SqlChannelStore.GetTeamChannels", "app.channel.get_channels.not_found.app_error", nil, "teamId="+teamId, http.StatusNotFound)
return nil, store.NewErrNotFound("Channel", fmt.Sprintf("teamId=%s", teamId))
}
return data, nil
@@ -2282,18 +2280,18 @@ func (s SqlChannelStore) IncrementMentionCount(channelId string, userId string)
return nil
}
func (s SqlChannelStore) GetAll(teamId string) ([]*model.Channel, *model.AppError) {
func (s SqlChannelStore) GetAll(teamId string) ([]*model.Channel, error) {
var data []*model.Channel
_, err := s.GetReplica().Select(&data, "SELECT * FROM Channels WHERE TeamId = :TeamId AND Type != 'D' ORDER BY Name", map[string]interface{}{"TeamId": teamId})
if err != nil {
return nil, model.NewAppError("SqlChannelStore.GetAll", "store.sql_channel.get_all.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError)
return nil, errors.Wrapf(err, "failed to find Channels with teamId=%s", teamId)
}
return data, nil
}
func (s SqlChannelStore) GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, *model.AppError) {
func (s SqlChannelStore) GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, error) {
keys, params := MapStringsToQueryParams(channelIds, "Channel")
query := `SELECT * FROM Channels WHERE Id IN ` + keys + ` ORDER BY Name`
if !includeDeleted {
@@ -2304,13 +2302,12 @@ func (s SqlChannelStore) GetChannelsByIds(channelIds []string, includeDeleted bo
_, err := s.GetReplica().Select(&channels, query, params)
if err != nil {
mlog.Error("Query error getting channels by ids", mlog.Err(err))
return nil, model.NewAppError("SqlChannelStore.GetChannelsByIds", "store.sql_channel.get_channels_by_ids.app_error", nil, "", http.StatusInternalServerError)
return nil, errors.Wrap(err, "failed to find Channels")
}
return channels, nil
}
func (s SqlChannelStore) GetForPost(postId string) (*model.Channel, *model.AppError) {
func (s SqlChannelStore) GetForPost(postId string) (*model.Channel, error) {
channel := &model.Channel{}
if err := s.GetReplica().SelectOne(
channel,
@@ -2322,7 +2319,7 @@ func (s SqlChannelStore) GetForPost(postId string) (*model.Channel, *model.AppEr
WHERE
Channels.Id = Posts.ChannelId
AND Posts.Id = :PostId`, map[string]interface{}{"PostId": postId}); err != nil {
return nil, model.NewAppError("SqlChannelStore.GetForPost", "store.sql_channel.get_for_post.app_error", nil, "postId="+postId+", err="+err.Error(), http.StatusInternalServerError)
return nil, errors.Wrapf(err, "failed to get Channel with postId=%s", postId)
}
return channel, nil

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

@@ -899,15 +899,15 @@ func (s SqlChannelStore) DeleteSidebarChannelsByPreferences(preferences *model.P
return nil
}
func (s SqlChannelStore) UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) *model.AppError {
func (s SqlChannelStore) UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) error {
// if channel is being moved, remove it from the categories, since it's possible that there's no matching category in the new team
if _, err := s.GetMaster().Exec("DELETE FROM SidebarChannels WHERE ChannelId=:ChannelId", map[string]interface{}{"ChannelId": channel.Id}); err != nil {
return model.NewAppError("SqlChannelStore.UpdateSidebarChannelCategoryOnMove", "store.sql_channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError)
return errors.Wrapf(err, "failed to delete SidebarChannels with channelId=%s", channel.Id)
}
return nil
}
func (s SqlChannelStore) ClearSidebarOnTeamLeave(userId, teamId string) *model.AppError {
func (s SqlChannelStore) ClearSidebarOnTeamLeave(userId, teamId string) error {
// if user leaves the team, clean his team related entries in sidebar channels and categories
params := map[string]interface{}{
"UserId": userId,
@@ -921,10 +921,10 @@ func (s SqlChannelStore) ClearSidebarOnTeamLeave(userId, teamId string) *model.A
deleteQuery = "DELETE FROM SidebarChannels USING SidebarChannels AS chan LEFT OUTER JOIN SidebarCategories AS cat ON cat.Id = chan.CategoryId WHERE cat.UserId = :UserId AND cat.TeamId = :TeamId"
}
if _, err := s.GetMaster().Exec(deleteQuery, params); err != nil {
return model.NewAppError("SqlChannelStore.ClearSidebarOnTeamLeave", "store.sql_channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError)
return errors.Wrap(err, "failed to delete from SidebarChannels")
}
if _, err := s.GetMaster().Exec("DELETE FROM SidebarCategories WHERE SidebarCategories.TeamId = :TeamId AND SidebarCategories.UserId = :UserId", params); err != nil {
return model.NewAppError("SqlChannelStore.ClearSidebarOnTeamLeave", "store.sql_channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError)
return errors.Wrap(err, "failed to delete from SidebarCategories")
}
return nil
}

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

@@ -134,8 +134,8 @@ type ChannelStore interface {
CreateDirectChannel(userId *model.User, otherUserId *model.User) (*model.Channel, error)
SaveDirectChannel(channel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) (*model.Channel, error)
Update(channel *model.Channel) (*model.Channel, error)
UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) *model.AppError
ClearSidebarOnTeamLeave(userId, teamId string) *model.AppError
UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) error
ClearSidebarOnTeamLeave(userId, teamId string) error
Get(id string, allowFromCache bool) (*model.Channel, error)
InvalidateChannel(id string)
InvalidateChannelByName(teamId, name string)
@@ -154,14 +154,14 @@ type ChannelStore interface {
GetAllChannels(page, perPage int, opts ChannelSearchOpts) (*model.ChannelListWithTeamData, error)
GetAllChannelsCount(opts ChannelSearchOpts) (int64, error)
GetMoreChannels(teamId string, userId string, offset int, limit int) (*model.ChannelList, error)
GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError)
GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError)
GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError)
GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError)
GetTeamChannels(teamId string) (*model.ChannelList, *model.AppError)
GetAll(teamId string) ([]*model.Channel, *model.AppError)
GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, *model.AppError)
GetForPost(postId string) (*model.Channel, *model.AppError)
GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, error)
GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, error)
GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, error)
GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, error)
GetTeamChannels(teamId string) (*model.ChannelList, error)
GetAll(teamId string) ([]*model.Channel, error)
GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, error)
GetForPost(postId string) (*model.Channel, error)
SaveMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, *model.AppError)
SaveMember(member *model.ChannelMember) (*model.ChannelMember, *model.AppError)
UpdateMember(member *model.ChannelMember) (*model.ChannelMember, *model.AppError)

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

@@ -3773,7 +3773,8 @@ func testChannelStoreGetPublicChannelsByIdsForTeam(t *testing.T, ss store.Store)
t.Run("random channel id should not be found as a public channel in the team", func(t *testing.T) {
_, err := ss.Channel().GetPublicChannelsByIdsForTeam(teamId, []string{model.NewId()})
require.NotNil(t, err)
require.Equal(t, "store.sql_channel.get_channels_by_ids.not_found.app_error", err.Id)
var nfErr *store.ErrNotFound
require.True(t, errors.As(err, &nfErr))
})
}

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

@@ -133,16 +133,14 @@ func (_m *ChannelStore) ClearCaches() {
}
// ClearSidebarOnTeamLeave provides a mock function with given fields: userId, teamId
func (_m *ChannelStore) ClearSidebarOnTeamLeave(userId string, teamId string) *model.AppError {
func (_m *ChannelStore) ClearSidebarOnTeamLeave(userId string, teamId string) error {
ret := _m.Called(userId, teamId)
var r0 *model.AppError
if rf, ok := ret.Get(0).(func(string, string) *model.AppError); ok {
var r0 error
if rf, ok := ret.Get(0).(func(string, string) error); ok {
r0 = rf(userId, teamId)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.AppError)
}
r0 = ret.Error(0)
}
return r0
@@ -301,7 +299,7 @@ func (_m *ChannelStore) Get(id string, allowFromCache bool) (*model.Channel, err
}
// GetAll provides a mock function with given fields: teamId
func (_m *ChannelStore) GetAll(teamId string) ([]*model.Channel, *model.AppError) {
func (_m *ChannelStore) GetAll(teamId string) ([]*model.Channel, error) {
ret := _m.Called(teamId)
var r0 []*model.Channel
@@ -313,13 +311,11 @@ func (_m *ChannelStore) GetAll(teamId string) ([]*model.Channel, *model.AppError
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
var r1 error
if rf, ok := ret.Get(1).(func(string) error); ok {
r1 = rf(teamId)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
r1 = ret.Error(1)
}
return r0, r1
@@ -539,7 +535,7 @@ func (_m *ChannelStore) GetByNames(team_id string, names []string, allowFromCach
}
// GetChannelCounts provides a mock function with given fields: teamId, userId
func (_m *ChannelStore) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError) {
func (_m *ChannelStore) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, error) {
ret := _m.Called(teamId, userId)
var r0 *model.ChannelCounts
@@ -551,13 +547,11 @@ func (_m *ChannelStore) GetChannelCounts(teamId string, userId string) (*model.C
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok {
var r1 error
if rf, ok := ret.Get(1).(func(string, string) error); ok {
r1 = rf(teamId, userId)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
r1 = ret.Error(1)
}
return r0, r1
@@ -687,7 +681,7 @@ func (_m *ChannelStore) GetChannelsBatchForIndexing(startTime int64, endTime int
}
// GetChannelsByIds provides a mock function with given fields: channelIds, includeDeleted
func (_m *ChannelStore) GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, *model.AppError) {
func (_m *ChannelStore) GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, error) {
ret := _m.Called(channelIds, includeDeleted)
var r0 []*model.Channel
@@ -699,13 +693,11 @@ func (_m *ChannelStore) GetChannelsByIds(channelIds []string, includeDeleted boo
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func([]string, bool) *model.AppError); ok {
var r1 error
if rf, ok := ret.Get(1).(func([]string, bool) error); ok {
r1 = rf(channelIds, includeDeleted)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
r1 = ret.Error(1)
}
return r0, r1
@@ -783,7 +775,7 @@ func (_m *ChannelStore) GetDeletedByName(team_id string, name string) (*model.Ch
}
// GetForPost provides a mock function with given fields: postId
func (_m *ChannelStore) GetForPost(postId string) (*model.Channel, *model.AppError) {
func (_m *ChannelStore) GetForPost(postId string) (*model.Channel, error) {
ret := _m.Called(postId)
var r0 *model.Channel
@@ -795,13 +787,11 @@ func (_m *ChannelStore) GetForPost(postId string) (*model.Channel, *model.AppErr
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
var r1 error
if rf, ok := ret.Get(1).(func(string) error); ok {
r1 = rf(postId)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
r1 = ret.Error(1)
}
return r0, r1
@@ -1137,7 +1127,7 @@ func (_m *ChannelStore) GetPinnedPosts(channelId string) (*model.PostList, *mode
}
// GetPrivateChannelsForTeam provides a mock function with given fields: teamId, offset, limit
func (_m *ChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
func (_m *ChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, error) {
ret := _m.Called(teamId, offset, limit)
var r0 *model.ChannelList
@@ -1149,20 +1139,18 @@ func (_m *ChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, lim
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, int, int) *model.AppError); ok {
var r1 error
if rf, ok := ret.Get(1).(func(string, int, int) error); ok {
r1 = rf(teamId, offset, limit)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
r1 = ret.Error(1)
}
return r0, r1
}
// GetPublicChannelsByIdsForTeam provides a mock function with given fields: teamId, channelIds
func (_m *ChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) {
func (_m *ChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, error) {
ret := _m.Called(teamId, channelIds)
var r0 *model.ChannelList
@@ -1174,20 +1162,18 @@ func (_m *ChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, []string) *model.AppError); ok {
var r1 error
if rf, ok := ret.Get(1).(func(string, []string) error); ok {
r1 = rf(teamId, channelIds)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
r1 = ret.Error(1)
}
return r0, r1
}
// GetPublicChannelsForTeam provides a mock function with given fields: teamId, offset, limit
func (_m *ChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
func (_m *ChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, error) {
ret := _m.Called(teamId, offset, limit)
var r0 *model.ChannelList
@@ -1199,13 +1185,11 @@ func (_m *ChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limi
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, int, int) *model.AppError); ok {
var r1 error
if rf, ok := ret.Get(1).(func(string, int, int) error); ok {
r1 = rf(teamId, offset, limit)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
r1 = ret.Error(1)
}
return r0, r1
@@ -1287,7 +1271,7 @@ func (_m *ChannelStore) GetSidebarCategoryOrder(userId string, teamId string) ([
}
// GetTeamChannels provides a mock function with given fields: teamId
func (_m *ChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, *model.AppError) {
func (_m *ChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, error) {
ret := _m.Called(teamId)
var r0 *model.ChannelList
@@ -1299,13 +1283,11 @@ func (_m *ChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, *mod
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
var r1 error
if rf, ok := ret.Get(1).(func(string) error); ok {
r1 = rf(teamId)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
r1 = ret.Error(1)
}
return r0, r1
@@ -2024,16 +2006,14 @@ func (_m *ChannelStore) UpdateSidebarCategoryOrder(userId string, teamId string,
}
// UpdateSidebarChannelCategoryOnMove provides a mock function with given fields: channel, newTeamId
func (_m *ChannelStore) UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) *model.AppError {
func (_m *ChannelStore) UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) error {
ret := _m.Called(channel, newTeamId)
var r0 *model.AppError
if rf, ok := ret.Get(0).(func(*model.Channel, string) *model.AppError); ok {
var r0 error
if rf, ok := ret.Get(0).(func(*model.Channel, string) error); ok {
r0 = rf(channel, newTeamId)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.AppError)
}
r0 = ret.Error(0)
}
return r0

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

@@ -553,7 +553,7 @@ func (s *TimerLayerChannelStore) ClearCaches() {
}
}
func (s *TimerLayerChannelStore) ClearSidebarOnTeamLeave(userId string, teamId string) *model.AppError {
func (s *TimerLayerChannelStore) ClearSidebarOnTeamLeave(userId string, teamId string) error {
start := timemodule.Now()
err := s.ChannelStore.ClearSidebarOnTeamLeave(userId, teamId)
@@ -697,7 +697,7 @@ func (s *TimerLayerChannelStore) Get(id string, allowFromCache bool) (*model.Cha
return result, err
}
func (s *TimerLayerChannelStore) GetAll(teamId string) ([]*model.Channel, *model.AppError) {
func (s *TimerLayerChannelStore) GetAll(teamId string) ([]*model.Channel, error) {
start := timemodule.Now()
result, err := s.ChannelStore.GetAll(teamId)
@@ -857,7 +857,7 @@ func (s *TimerLayerChannelStore) GetByNames(team_id string, names []string, allo
return result, err
}
func (s *TimerLayerChannelStore) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError) {
func (s *TimerLayerChannelStore) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, error) {
start := timemodule.Now()
result, err := s.ChannelStore.GetChannelCounts(teamId, userId)
@@ -953,7 +953,7 @@ func (s *TimerLayerChannelStore) GetChannelsBatchForIndexing(startTime int64, en
return result, err
}
func (s *TimerLayerChannelStore) GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, *model.AppError) {
func (s *TimerLayerChannelStore) GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, error) {
start := timemodule.Now()
result, err := s.ChannelStore.GetChannelsByIds(channelIds, includeDeleted)
@@ -1017,7 +1017,7 @@ func (s *TimerLayerChannelStore) GetDeletedByName(team_id string, name string) (
return result, err
}
func (s *TimerLayerChannelStore) GetForPost(postId string) (*model.Channel, *model.AppError) {
func (s *TimerLayerChannelStore) GetForPost(postId string) (*model.Channel, error) {
start := timemodule.Now()
result, err := s.ChannelStore.GetForPost(postId)
@@ -1257,7 +1257,7 @@ func (s *TimerLayerChannelStore) GetPinnedPosts(channelId string) (*model.PostLi
return result, err
}
func (s *TimerLayerChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
func (s *TimerLayerChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, error) {
start := timemodule.Now()
result, err := s.ChannelStore.GetPrivateChannelsForTeam(teamId, offset, limit)
@@ -1273,7 +1273,7 @@ func (s *TimerLayerChannelStore) GetPrivateChannelsForTeam(teamId string, offset
return result, err
}
func (s *TimerLayerChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) {
func (s *TimerLayerChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, error) {
start := timemodule.Now()
result, err := s.ChannelStore.GetPublicChannelsByIdsForTeam(teamId, channelIds)
@@ -1289,7 +1289,7 @@ func (s *TimerLayerChannelStore) GetPublicChannelsByIdsForTeam(teamId string, ch
return result, err
}
func (s *TimerLayerChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
func (s *TimerLayerChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, error) {
start := timemodule.Now()
result, err := s.ChannelStore.GetPublicChannelsForTeam(teamId, offset, limit)
@@ -1353,7 +1353,7 @@ func (s *TimerLayerChannelStore) GetSidebarCategoryOrder(userId string, teamId s
return result, err
}
func (s *TimerLayerChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, *model.AppError) {
func (s *TimerLayerChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, error) {
start := timemodule.Now()
result, err := s.ChannelStore.GetTeamChannels(teamId)
@@ -2002,7 +2002,7 @@ func (s *TimerLayerChannelStore) UpdateSidebarCategoryOrder(userId string, teamI
return err
}
func (s *TimerLayerChannelStore) UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) *model.AppError {
func (s *TimerLayerChannelStore) UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) error {
start := timemodule.Now()
err := s.ChannelStore.UpdateSidebarChannelCategoryOnMove(channel, newTeamId)