GH-11469 Migrate User.UpdateLastPictureUpdate to Sync by default (#11493)

* GH-11469 Migrate User.UpdateLastPictureUpdate to Sync by default

* GH-11469 log error on failure
Этот коммит содержится в:
Marc Argent
2019-07-04 13:59:10 +01:00
коммит произвёл Jesús Espino
родитель 68703f9b76
Коммит 2f9d509284
5 изменённых файлов: 16 добавлений и 16 удалений

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

@@ -904,7 +904,9 @@ func (a *App) SetProfileImageFromFile(userId string, file io.Reader) *model.AppE
return model.NewAppError("SetProfileImage", "api.user.upload_profile_user.upload_profile.app_error", nil, "", http.StatusInternalServerError)
}
<-a.Srv.Store.User().UpdateLastPictureUpdate(userId)
if err := a.Srv.Store.User().UpdateLastPictureUpdate(userId); err != nil {
mlog.Error(err.Error())
}
a.InvalidateCacheForUser(userId)

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

@@ -212,16 +212,14 @@ func (us SqlUserStore) Update(user *model.User, trustedUpdateData bool) (*model.
return &model.UserUpdate{New: user, Old: oldUser}, nil
}
func (us SqlUserStore) UpdateLastPictureUpdate(userId string) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
curTime := model.GetMillis()
func (us SqlUserStore) UpdateLastPictureUpdate(userId string) *model.AppError {
curTime := model.GetMillis()
if _, err := us.GetMaster().Exec("UPDATE Users SET LastPictureUpdate = :Time, UpdateAt = :Time WHERE Id = :UserId", map[string]interface{}{"Time": curTime, "UserId": userId}); err != nil {
result.Err = model.NewAppError("SqlUserStore.UpdateLastPictureUpdate", "store.sql_user.update_last_picture_update.app_error", nil, "user_id="+userId, http.StatusInternalServerError)
} else {
result.Data = userId
}
})
if _, err := us.GetMaster().Exec("UPDATE Users SET LastPictureUpdate = :Time, UpdateAt = :Time WHERE Id = :UserId", map[string]interface{}{"Time": curTime, "UserId": userId}); err != nil {
return model.NewAppError("SqlUserStore.UpdateLastPictureUpdate", "store.sql_user.update_last_picture_update.app_error", nil, "user_id="+userId, http.StatusInternalServerError)
}
return nil
}
func (us SqlUserStore) ResetLastPictureUpdate(userId string) *model.AppError {

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

@@ -251,7 +251,7 @@ type PostStore interface {
type UserStore interface {
Save(user *model.User) StoreChannel
Update(user *model.User, allowRoleUpdate bool) (*model.UserUpdate, *model.AppError)
UpdateLastPictureUpdate(userId string) StoreChannel
UpdateLastPictureUpdate(userId string) *model.AppError
ResetLastPictureUpdate(userId string) *model.AppError
UpdateUpdateAt(userId string) StoreChannel
UpdatePassword(userId, newPassword string) StoreChannel

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

@@ -1043,15 +1043,15 @@ func (_m *UserStore) UpdateFailedPasswordAttempts(userId string, attempts int) s
}
// UpdateLastPictureUpdate provides a mock function with given fields: userId
func (_m *UserStore) UpdateLastPictureUpdate(userId string) store.StoreChannel {
func (_m *UserStore) UpdateLastPictureUpdate(userId string) *model.AppError {
ret := _m.Called(userId)
var r0 store.StoreChannel
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
var r0 *model.AppError
if rf, ok := ret.Get(0).(func(string) *model.AppError); ok {
r0 = rf(userId)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel)
r0 = ret.Get(0).(*model.AppError)
}
}

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

@@ -203,7 +203,7 @@ func testUserStoreUpdate(t *testing.T, ss store.Store) {
}
}
if result := <-ss.User().UpdateLastPictureUpdate(u1.Id); result.Err != nil {
if err := ss.User().UpdateLastPictureUpdate(u1.Id); err != nil {
t.Fatal("Update should not have failed")
}
}