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) 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) 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 return &model.UserUpdate{New: user, Old: oldUser}, nil
} }
func (us SqlUserStore) UpdateLastPictureUpdate(userId string) store.StoreChannel { func (us SqlUserStore) UpdateLastPictureUpdate(userId string) *model.AppError {
return store.Do(func(result *store.StoreResult) { curTime := model.GetMillis()
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 { 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) return model.NewAppError("SqlUserStore.UpdateLastPictureUpdate", "store.sql_user.update_last_picture_update.app_error", nil, "user_id="+userId, http.StatusInternalServerError)
} else { }
result.Data = userId
} return nil
})
} }
func (us SqlUserStore) ResetLastPictureUpdate(userId string) *model.AppError { func (us SqlUserStore) ResetLastPictureUpdate(userId string) *model.AppError {

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

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

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

@@ -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") t.Fatal("Update should not have failed")
} }
} }