Migrate multiples methods from ChannelStore to return error interface (#14708)
Automatic Merge
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
09a0b7db61
Коммит
e342b5a2f2
@@ -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)
|
||||
|
||||
Ссылка в новой задаче
Block a user