[MM-15296] Migrate "Preference.Save" to Sync by default (#10866)

* response format changes

* Generated mocks
Fixed all references of Preferences.Save

* Remove old code from store.go (incorrect merge)

* Review change - Add validations on count and error

* Review change - return from root level

* Review change - return 0 as nil value for int

* fix initialisation of err in preference_store
Этот коммит содержится в:
Ishank Gulati
2019-05-26 18:36:33 +05:30
коммит произвёл Jesús Espino
родитель c05cf5b033
Коммит fb6c1debf0
15 изменённых файлов: 150 добавлений и 86 удалений

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

@@ -54,31 +54,25 @@ func (s SqlPreferenceStore) DeleteUnusedFeatures() {
s.GetMaster().Exec(sql, queryParams)
}
func (s SqlPreferenceStore) Save(preferences *model.Preferences) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
// wrap in a transaction so that if one fails, everything fails
transaction, err := s.GetMaster().Begin()
if err != nil {
result.Err = model.NewAppError("SqlPreferenceStore.Save", "store.sql_preference.save.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
} else {
defer finalizeTransaction(transaction)
for _, preference := range *preferences {
if upsertResult := s.save(transaction, &preference); upsertResult.Err != nil {
*result = upsertResult
break
}
}
func (s SqlPreferenceStore) Save(preferences *model.Preferences) (int, *model.AppError) {
// wrap in a transaction so that if one fails, everything fails
transaction, err := s.GetMaster().Begin()
if err != nil {
return 0, model.NewAppError("SqlPreferenceStore.Save", "store.sql_preference.save.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
}
if result.Err == nil {
if err := transaction.Commit(); err != nil {
// don't need to rollback here since the transaction is already closed
result.Err = model.NewAppError("SqlPreferenceStore.Save", "store.sql_preference.save.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
} else {
result.Data = len(*preferences)
}
}
defer finalizeTransaction(transaction)
for _, preference := range *preferences {
if upsertResult := s.save(transaction, &preference); upsertResult.Err != nil {
return 0, upsertResult.Err
}
})
}
if err := transaction.Commit(); err != nil {
// don't need to rollback here since the transaction is already closed
return 0, model.NewAppError("SqlPreferenceStore.Save", "store.sql_preference.save.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return len(*preferences), nil
}
func (s SqlPreferenceStore) save(transaction *gorp.Transaction, preference *model.Preference) store.StoreResult {