[MM-15300] Migrate "Preference.PermanentDeleteByUser" to Sync by default (#10860)

* [MM-15300] Migrate "Preference.PermanentDeleteByUser" to Sync by default

* [MM-15300] Fixed readability on the SQL statement
Этот коммит содержится в:
Devin Binnie
2019-05-20 07:46:41 -04:00
коммит произвёл Jesús Espino
родитель 18612bf771
Коммит 9652b49569
5 изменённых файлов: 21 добавлений и 16 удалений

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

@@ -1435,8 +1435,8 @@ func (a *App) PermanentDeleteUser(user *model.User) *model.AppError {
return err return err
} }
if result := <-a.Srv.Store.Preference().PermanentDeleteByUser(user.Id); result.Err != nil { if err := a.Srv.Store.Preference().PermanentDeleteByUser(user.Id); err != nil {
return result.Err return err
} }
if result := <-a.Srv.Store.Channel().PermanentDeleteMembersByUser(user.Id); result.Err != nil { if result := <-a.Srv.Store.Channel().PermanentDeleteMembersByUser(user.Id); result.Err != nil {

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

@@ -216,13 +216,18 @@ func (s SqlPreferenceStore) GetAll(userId string) store.StoreChannel {
}) })
} }
func (s SqlPreferenceStore) PermanentDeleteByUser(userId string) store.StoreChannel { func (s SqlPreferenceStore) PermanentDeleteByUser(userId string) *model.AppError {
return store.Do(func(result *store.StoreResult) { query :=
if _, err := s.GetMaster().Exec( `DELETE FROM
`DELETE FROM Preferences WHERE UserId = :UserId`, map[string]interface{}{"UserId": userId}); err != nil { Preferences
result.Err = model.NewAppError("SqlPreferenceStore.Delete", "store.sql_preference.permanent_delete_by_user.app_error", nil, err.Error(), http.StatusInternalServerError) WHERE
} UserId = :UserId`
})
if _, err := s.GetMaster().Exec(query, map[string]interface{}{"UserId": userId}); err != nil {
return model.NewAppError("SqlPreferenceStore.Delete", "store.sql_preference.permanent_delete_by_user.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return nil
} }
func (s SqlPreferenceStore) IsFeatureEnabled(feature, userId string) store.StoreChannel { func (s SqlPreferenceStore) IsFeatureEnabled(feature, userId string) store.StoreChannel {

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

@@ -435,7 +435,7 @@ type PreferenceStore interface {
Delete(userId, category, name string) StoreChannel Delete(userId, category, name string) StoreChannel
DeleteCategory(userId string, category string) StoreChannel DeleteCategory(userId string, category string) StoreChannel
DeleteCategoryAndName(category string, name string) StoreChannel DeleteCategoryAndName(category string, name string) StoreChannel
PermanentDeleteByUser(userId string) StoreChannel PermanentDeleteByUser(userId string) *model.AppError
IsFeatureEnabled(feature, userId string) StoreChannel IsFeatureEnabled(feature, userId string) StoreChannel
CleanupFlagsBatch(limit int64) StoreChannel CleanupFlagsBatch(limit int64) StoreChannel
} }

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

@@ -160,15 +160,15 @@ func (_m *PreferenceStore) IsFeatureEnabled(feature string, userId string) store
} }
// PermanentDeleteByUser provides a mock function with given fields: userId // PermanentDeleteByUser provides a mock function with given fields: userId
func (_m *PreferenceStore) PermanentDeleteByUser(userId string) store.StoreChannel { func (_m *PreferenceStore) PermanentDeleteByUser(userId string) *model.AppError {
ret := _m.Called(userId) ret := _m.Called(userId)
var r0 store.StoreChannel var r0 *model.AppError
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok { if rf, ok := ret.Get(0).(func(string) *model.AppError); ok {
r0 = rf(userId) r0 = rf(userId)
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel) r0 = ret.Get(0).(*model.AppError)
} }
} }

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

@@ -235,8 +235,8 @@ func testPreferenceDeleteByUser(t *testing.T, ss store.Store) {
store.Must(ss.Preference().Save(&preferences)) store.Must(ss.Preference().Save(&preferences))
if result := <-ss.Preference().PermanentDeleteByUser(userId); result.Err != nil { if err := ss.Preference().PermanentDeleteByUser(userId); err != nil {
t.Fatal(result.Err) t.Fatal(err)
} }
} }