Migrate multiples methods from ChannelStore to return error interface (#14708)

Automatic Merge
Этот коммит содержится в:
Rodrigo Villablanca
2020-06-16 04:56:35 -04:00
коммит произвёл GitHub
родитель 09a0b7db61
Коммит e342b5a2f2
16 изменённых файлов: 105 добавлений и 90 удалений

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

@@ -4,7 +4,6 @@
package store
const (
MISSING_CHANNEL_ERROR = "store.sql_channel.get_by_name.missing.app_error"
MISSING_CHANNEL_MEMBER_ERROR = "store.sql_channel.get_member.missing.app_error"
CHANNEL_EXISTS_ERROR = "store.sql_channel.save_channel.exists.app_error"

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

@@ -774,7 +774,7 @@ func (s *OpenTracingLayerChannelStore) GetAllDirectChannelsForExportAfter(limit
return resultVar0, resultVar1
}
func (s *OpenTracingLayerChannelStore) GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError) {
func (s *OpenTracingLayerChannelStore) GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetByName")
s.Root.Store.SetContext(newCtx)
@@ -792,7 +792,7 @@ func (s *OpenTracingLayerChannelStore) GetByName(team_id string, name string, al
return resultVar0, resultVar1
}
func (s *OpenTracingLayerChannelStore) GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError) {
func (s *OpenTracingLayerChannelStore) GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) (*model.Channel, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetByNameIncludeDeleted")
s.Root.Store.SetContext(newCtx)
@@ -810,7 +810,7 @@ func (s *OpenTracingLayerChannelStore) GetByNameIncludeDeleted(team_id string, n
return resultVar0, resultVar1
}
func (s *OpenTracingLayerChannelStore) GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, *model.AppError) {
func (s *OpenTracingLayerChannelStore) GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetByNames")
s.Root.Store.SetContext(newCtx)

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

@@ -1151,11 +1151,11 @@ func (s SqlChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, *mo
return data, nil
}
func (s SqlChannelStore) GetByName(teamId string, name string, allowFromCache bool) (*model.Channel, *model.AppError) {
func (s SqlChannelStore) GetByName(teamId string, name string, allowFromCache bool) (*model.Channel, error) {
return s.getByName(teamId, name, false, allowFromCache)
}
func (s SqlChannelStore) GetByNames(teamId string, names []string, allowFromCache bool) ([]*model.Channel, *model.AppError) {
func (s SqlChannelStore) GetByNames(teamId string, names []string, allowFromCache bool) ([]*model.Channel, error) {
var channels []*model.Channel
if allowFromCache {
@@ -1195,7 +1195,11 @@ func (s SqlChannelStore) GetByNames(teamId string, names []string, allowFromCach
var dbChannels []*model.Channel
if _, err := s.GetReplica().Select(&dbChannels, query, props); err != nil && err != sql.ErrNoRows {
return nil, model.NewAppError("SqlChannelStore.GetByName", "store.sql_channel.get_by_name.existing.app_error", nil, "teamId="+teamId+", "+err.Error(), http.StatusInternalServerError)
msg := fmt.Sprintf("failed to get channels with names=%v", names)
if teamId != "" {
msg += fmt.Sprintf("teamId=%s", teamId)
}
return nil, errors.Wrap(err, msg)
}
for _, channel := range dbChannels {
channelByNameCache.SetWithExpiry(teamId+channel.Name, channel, CHANNEL_CACHE_DURATION)
@@ -1215,11 +1219,11 @@ func (s SqlChannelStore) GetByNames(teamId string, names []string, allowFromCach
return channels, nil
}
func (s SqlChannelStore) GetByNameIncludeDeleted(teamId string, name string, allowFromCache bool) (*model.Channel, *model.AppError) {
func (s SqlChannelStore) GetByNameIncludeDeleted(teamId string, name string, allowFromCache bool) (*model.Channel, error) {
return s.getByName(teamId, name, true, allowFromCache)
}
func (s SqlChannelStore) getByName(teamId string, name string, includeDeleted bool, allowFromCache bool) (*model.Channel, *model.AppError) {
func (s SqlChannelStore) getByName(teamId string, name string, includeDeleted bool, allowFromCache bool) (*model.Channel, error) {
var query string
if includeDeleted {
query = "SELECT * FROM Channels WHERE (TeamId = :TeamId OR TeamId = '') AND Name = :Name"
@@ -1243,9 +1247,9 @@ func (s SqlChannelStore) getByName(teamId string, name string, includeDeleted bo
if err := s.GetReplica().SelectOne(&channel, query, map[string]interface{}{"TeamId": teamId, "Name": name}); err != nil {
if err == sql.ErrNoRows {
return nil, model.NewAppError("SqlChannelStore.GetByName", store.MISSING_CHANNEL_ERROR, nil, "teamId="+teamId+", "+"name="+name+"", http.StatusNotFound)
return nil, store.NewErrNotFound("Channel", fmt.Sprintf("TeamId=%s&Name=%s", teamId, name))
}
return nil, model.NewAppError("SqlChannelStore.GetByName", "store.sql_channel.get_by_name.existing.app_error", nil, "teamId="+teamId+", "+"name="+name+", "+err.Error(), http.StatusInternalServerError)
return nil, errors.Wrapf(err, "failed to find channel with TeamId=%s and Name=%s", teamId, name)
}
channelByNameCache.SetWithExpiry(teamId+name, &channel, CHANNEL_CACHE_DURATION)

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

@@ -143,9 +143,9 @@ type ChannelStore interface {
SetDeleteAt(channelId string, deleteAt int64, updateAt int64) error
PermanentDelete(channelId string) error
PermanentDeleteByTeam(teamId string) error
GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError)
GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, *model.AppError)
GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError)
GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, error)
GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, error)
GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) (*model.Channel, error)
GetDeletedByName(team_id string, name string) (*model.Channel, *model.AppError)
GetDeleted(team_id string, offset int, limit int, userId string) (*model.ChannelList, error)
GetChannels(teamId string, userId string, includeDeleted bool) (*model.ChannelList, error)

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

@@ -714,8 +714,8 @@ func testChannelStoreGetByNames(t *testing.T, ss store.Store) {
err = ss.Channel().Delete(o2.Id, model.GetMillis())
require.Nil(t, err, "channel should have been deleted")
channels, err := ss.Channel().GetByNames(o1.TeamId, []string{o1.Name}, false)
require.Nil(t, err)
channels, nErr := ss.Channel().GetByNames(o1.TeamId, []string{o1.Name}, false)
require.Nil(t, nErr)
assert.Empty(t, channels)
}

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

@@ -385,7 +385,7 @@ func (_m *ChannelStore) GetAllDirectChannelsForExportAfter(limit int, afterId st
}
// GetByName provides a mock function with given fields: team_id, name, allowFromCache
func (_m *ChannelStore) GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError) {
func (_m *ChannelStore) GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, error) {
ret := _m.Called(team_id, name, allowFromCache)
var r0 *model.Channel
@@ -397,20 +397,18 @@ func (_m *ChannelStore) GetByName(team_id string, name string, allowFromCache bo
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, string, bool) *model.AppError); ok {
var r1 error
if rf, ok := ret.Get(1).(func(string, string, bool) error); ok {
r1 = rf(team_id, name, allowFromCache)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
r1 = ret.Error(1)
}
return r0, r1
}
// GetByNameIncludeDeleted provides a mock function with given fields: team_id, name, allowFromCache
func (_m *ChannelStore) GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError) {
func (_m *ChannelStore) GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) (*model.Channel, error) {
ret := _m.Called(team_id, name, allowFromCache)
var r0 *model.Channel
@@ -422,20 +420,18 @@ func (_m *ChannelStore) GetByNameIncludeDeleted(team_id string, name string, all
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, string, bool) *model.AppError); ok {
var r1 error
if rf, ok := ret.Get(1).(func(string, string, bool) error); ok {
r1 = rf(team_id, name, allowFromCache)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
r1 = ret.Error(1)
}
return r0, r1
}
// GetByNames provides a mock function with given fields: team_id, names, allowFromCache
func (_m *ChannelStore) GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, *model.AppError) {
func (_m *ChannelStore) GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, error) {
ret := _m.Called(team_id, names, allowFromCache)
var r0 []*model.Channel
@@ -447,13 +443,11 @@ func (_m *ChannelStore) GetByNames(team_id string, names []string, allowFromCach
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, []string, bool) *model.AppError); ok {
var r1 error
if rf, ok := ret.Get(1).(func(string, []string, bool) error); ok {
r1 = rf(team_id, names, allowFromCache)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
r1 = ret.Error(1)
}
return r0, r1

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

@@ -728,7 +728,7 @@ func (s *TimerLayerChannelStore) GetAllDirectChannelsForExportAfter(limit int, a
return resultVar0, resultVar1
}
func (s *TimerLayerChannelStore) GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError) {
func (s *TimerLayerChannelStore) GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, error) {
start := timemodule.Now()
resultVar0, resultVar1 := s.ChannelStore.GetByName(team_id, name, allowFromCache)
@@ -744,7 +744,7 @@ func (s *TimerLayerChannelStore) GetByName(team_id string, name string, allowFro
return resultVar0, resultVar1
}
func (s *TimerLayerChannelStore) GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError) {
func (s *TimerLayerChannelStore) GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) (*model.Channel, error) {
start := timemodule.Now()
resultVar0, resultVar1 := s.ChannelStore.GetByNameIncludeDeleted(team_id, name, allowFromCache)
@@ -760,7 +760,7 @@ func (s *TimerLayerChannelStore) GetByNameIncludeDeleted(team_id string, name st
return resultVar0, resultVar1
}
func (s *TimerLayerChannelStore) GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, *model.AppError) {
func (s *TimerLayerChannelStore) GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, error) {
start := timemodule.Now()
resultVar0, resultVar1 := s.ChannelStore.GetByNames(team_id, names, allowFromCache)