Migrate Get/GetFromMaster methods from ChannelStore to return error interface (#14688)
* Advances * Migration finished * Rename err to normalized error * fix imports * Renamed key * Renamed key * Suggestions * Fix i18n * Fix tests Co-authored-by: Jesús Espino <jespinog@gmail.com> Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
60cc775cf6
Коммит
85a69d6112
@@ -150,7 +150,7 @@ func (s LocalCacheChannelStore) GetPinnedPostCount(channelId string, allowFromCa
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (s LocalCacheChannelStore) Get(id string, allowFromCache bool) (*model.Channel, *model.AppError) {
|
||||
func (s LocalCacheChannelStore) Get(id string, allowFromCache bool) (*model.Channel, error) {
|
||||
|
||||
if allowFromCache {
|
||||
if cacheItem := s.rootStore.doStandardReadCache(s.rootStore.channelByIdCache, id); cacheItem != nil {
|
||||
|
||||
@@ -630,7 +630,7 @@ func (s *OpenTracingLayerChannelStore) Delete(channelId string, time int64) *mod
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerChannelStore) Get(id string, allowFromCache bool) (*model.Channel, *model.AppError) {
|
||||
func (s *OpenTracingLayerChannelStore) Get(id string, allowFromCache bool) (*model.Channel, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.Get")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -1026,7 +1026,7 @@ func (s *OpenTracingLayerChannelStore) GetForPost(postId string) (*model.Channel
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerChannelStore) GetFromMaster(id string) (*model.Channel, *model.AppError) {
|
||||
func (s *OpenTracingLayerChannelStore) GetFromMaster(id string) (*model.Channel, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetFromMaster")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
|
||||
@@ -725,7 +725,7 @@ func (s SqlChannelStore) InvalidateChannelByName(teamId, name string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) Get(id string, allowFromCache bool) (*model.Channel, *model.AppError) {
|
||||
func (s SqlChannelStore) Get(id string, allowFromCache bool) (*model.Channel, error) {
|
||||
return s.get(id, false, allowFromCache)
|
||||
}
|
||||
|
||||
@@ -743,11 +743,11 @@ func (s SqlChannelStore) GetPinnedPosts(channelId string) (*model.PostList, *mod
|
||||
return pl, nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetFromMaster(id string) (*model.Channel, *model.AppError) {
|
||||
func (s SqlChannelStore) GetFromMaster(id string) (*model.Channel, error) {
|
||||
return s.get(id, true, false)
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) get(id string, master bool, allowFromCache bool) (*model.Channel, *model.AppError) {
|
||||
func (s SqlChannelStore) get(id string, master bool, allowFromCache bool) (*model.Channel, error) {
|
||||
var db *gorp.DbMap
|
||||
|
||||
if master {
|
||||
@@ -758,11 +758,11 @@ func (s SqlChannelStore) get(id string, master bool, allowFromCache bool) (*mode
|
||||
|
||||
obj, err := db.Get(model.Channel{}, id)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlChannelStore.Get", "store.sql_channel.get.find.app_error", nil, "id="+id+", "+err.Error(), http.StatusInternalServerError)
|
||||
return nil, errors.Wrapf(err, "failed to find channel with id = %s", id)
|
||||
}
|
||||
|
||||
if obj == nil {
|
||||
return nil, model.NewAppError("SqlChannelStore.Get", "store.sql_channel.get.existing.app_error", nil, "id="+id, http.StatusNotFound)
|
||||
return nil, store.NewErrNotFound("Channel", id)
|
||||
}
|
||||
|
||||
ch := obj.(*model.Channel)
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
@@ -480,7 +481,13 @@ func (s *SqlGroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable)
|
||||
insertErr = s.GetMaster().Insert(groupSyncableToGroupTeam(groupSyncable))
|
||||
case model.GroupSyncableTypeChannel:
|
||||
if _, err := s.Channel().Get(groupSyncable.SyncableId, false); err != nil {
|
||||
return nil, err
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(err, &nfErr):
|
||||
return nil, model.NewAppError("CreateGroupSyncable", "store.sql_channel.get.existing.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
default:
|
||||
return nil, model.NewAppError("CreateGroupSyncable", "store.sql_channel.get.find.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
insertErr = s.GetMaster().Insert(groupSyncableToGroupChannel(groupSyncable))
|
||||
|
||||
@@ -15,6 +15,9 @@ import (
|
||||
type StoreResult struct {
|
||||
Data interface{}
|
||||
Err *model.AppError
|
||||
|
||||
// NErr a temporary field used by the new code for the AppError migration. This will later become Err when the entire store is migrated.
|
||||
NErr error
|
||||
}
|
||||
|
||||
type Store interface {
|
||||
@@ -131,10 +134,10 @@ 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)
|
||||
Get(id string, allowFromCache bool) (*model.Channel, *model.AppError)
|
||||
Get(id string, allowFromCache bool) (*model.Channel, error)
|
||||
InvalidateChannel(id string)
|
||||
InvalidateChannelByName(teamId, name string)
|
||||
GetFromMaster(id string) (*model.Channel, *model.AppError)
|
||||
GetFromMaster(id string) (*model.Channel, error)
|
||||
Delete(channelId string, time int64) *model.AppError
|
||||
Restore(channelId string, time int64) *model.AppError
|
||||
SetDeleteAt(channelId string, deleteAt int64, updateAt int64) *model.AppError
|
||||
|
||||
@@ -195,7 +195,7 @@ func (_m *ChannelStore) Delete(channelId string, time int64) *model.AppError {
|
||||
}
|
||||
|
||||
// Get provides a mock function with given fields: id, allowFromCache
|
||||
func (_m *ChannelStore) Get(id string, allowFromCache bool) (*model.Channel, *model.AppError) {
|
||||
func (_m *ChannelStore) Get(id string, allowFromCache bool) (*model.Channel, error) {
|
||||
ret := _m.Called(id, allowFromCache)
|
||||
|
||||
var r0 *model.Channel
|
||||
@@ -207,13 +207,11 @@ func (_m *ChannelStore) Get(id string, allowFromCache bool) (*model.Channel, *mo
|
||||
}
|
||||
}
|
||||
|
||||
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(id, allowFromCache)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
@@ -743,7 +741,7 @@ func (_m *ChannelStore) GetForPost(postId string) (*model.Channel, *model.AppErr
|
||||
}
|
||||
|
||||
// GetFromMaster provides a mock function with given fields: id
|
||||
func (_m *ChannelStore) GetFromMaster(id string) (*model.Channel, *model.AppError) {
|
||||
func (_m *ChannelStore) GetFromMaster(id string) (*model.Channel, error) {
|
||||
ret := _m.Called(id)
|
||||
|
||||
var r0 *model.Channel
|
||||
@@ -755,13 +753,11 @@ func (_m *ChannelStore) GetFromMaster(id string) (*model.Channel, *model.AppErro
|
||||
}
|
||||
}
|
||||
|
||||
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(id)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
|
||||
@@ -450,8 +450,8 @@ func testSchemeStoreDelete(t *testing.T, ss store.Store) {
|
||||
_, err = ss.Scheme().Delete(d5.Id)
|
||||
assert.Nil(t, err)
|
||||
|
||||
c6, err := ss.Channel().Get(c5.Id, true)
|
||||
assert.Nil(t, err)
|
||||
c6, nErr := ss.Channel().Get(c5.Id, true)
|
||||
assert.Nil(t, nErr)
|
||||
assert.Equal(t, "", *c6.SchemeId)
|
||||
}
|
||||
|
||||
|
||||
@@ -600,7 +600,7 @@ func (s *TimerLayerChannelStore) Delete(channelId string, time int64) *model.App
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelStore) Get(id string, allowFromCache bool) (*model.Channel, *model.AppError) {
|
||||
func (s *TimerLayerChannelStore) Get(id string, allowFromCache bool) (*model.Channel, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0, resultVar1 := s.ChannelStore.Get(id, allowFromCache)
|
||||
@@ -952,7 +952,7 @@ func (s *TimerLayerChannelStore) GetForPost(postId string) (*model.Channel, *mod
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelStore) GetFromMaster(id string) (*model.Channel, *model.AppError) {
|
||||
func (s *TimerLayerChannelStore) GetFromMaster(id string) (*model.Channel, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0, resultVar1 := s.ChannelStore.GetFromMaster(id)
|
||||
|
||||
Ссылка в новой задаче
Block a user