MM-15354: Migrate Channel.Save to sync by default (#10871)

* MM-15354: Migrate Channel.Save() to sync by default

* MM-15354: fix unchanged Channel().Save() methods

* fix typo

* fix nil reference bug and update tests for channels

* fix err shadowing bug

* MM-15354 fix support for sync version of Save
Этот коммит содержится в:
Andres Orozco
2019-05-27 11:54:04 -04:00
коммит произвёл Jesús Espino
родитель d28f56c61e
Коммит ff0d3ab00b
14 изменённых файлов: 515 добавлений и 322 удалений

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

@@ -450,41 +450,44 @@ func (s SqlChannelStore) upsertPublicChannelT(transaction *gorp.Transaction, cha
}
// Save writes the (non-direct) channel channel to the database.
func (s SqlChannelStore) Save(channel *model.Channel, maxChannelsPerTeam int64) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
if channel.DeleteAt != 0 {
result.Err = model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save.archived_channel.app_error", nil, "", http.StatusBadRequest)
return
}
func (s SqlChannelStore) Save(channel *model.Channel, maxChannelsPerTeam int64) (*model.Channel, *model.AppError) {
if channel.Type == model.CHANNEL_DIRECT {
result.Err = model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save.direct_channel.app_error", nil, "", http.StatusBadRequest)
return
}
if channel.DeleteAt != 0 {
return nil, model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save.archived_channel.app_error", nil, "", http.StatusBadRequest)
}
transaction, err := s.GetMaster().Begin()
if err != nil {
result.Err = model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
return
}
defer finalizeTransaction(transaction)
if channel.Type == model.CHANNEL_DIRECT {
return nil, model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save.direct_channel.app_error", nil, "", http.StatusBadRequest)
}
*result = s.saveChannelT(transaction, channel, maxChannelsPerTeam)
if result.Err != nil {
return
}
transaction, err := s.GetMaster().Begin()
if err != nil {
return nil, model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
}
defer finalizeTransaction(transaction)
// Additionally propagate the write to the PublicChannels table.
if err := s.upsertPublicChannelT(transaction, result.Data.(*model.Channel)); err != nil {
result.Err = model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save.upsert_public_channel.app_error", nil, err.Error(), http.StatusInternalServerError)
return
}
channelResult := s.saveChannelT(transaction, channel, maxChannelsPerTeam)
var newChannel *model.Channel
if channelResult.Data != nil {
newChannel = channelResult.Data.(*model.Channel)
}
appErr := channelResult.Err
if err := transaction.Commit(); err != nil {
result.Err = model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
return
}
})
if appErr != nil {
return newChannel, appErr
}
// Additionally propagate the write to the PublicChannels table.
if err := s.upsertPublicChannelT(transaction, newChannel); err != nil {
return nil, model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save.upsert_public_channel.app_error", nil, err.Error(), http.StatusInternalServerError)
}
if err := transaction.Commit(); err != nil {
return nil, model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return newChannel, nil
}
func (s SqlChannelStore) CreateDirectChannel(userId string, otherUserId string) (*model.Channel, *model.AppError) {