Migrate User.GetEtagForAllProfiles to sync by default (#11509)

Этот коммит содержится в:
Rodrigo Villablanca Vásquez
2019-07-04 08:30:23 -04:00
коммит произвёл Jesús Espino
родитель 9839b46889
Коммит cf695095d8
5 изменённых файлов: 14 добавлений и 24 удалений

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

@@ -460,7 +460,7 @@ func (a *App) GetUsersPage(options *model.UserGetOptions, asAdmin bool) ([]*mode
} }
func (a *App) GetUsersEtag(restrictionsHash string) string { func (a *App) GetUsersEtag(restrictionsHash string) string {
return fmt.Sprintf("%v.%v.%v.%v", (<-a.Srv.Store.User().GetEtagForAllProfiles()).Data.(string), a.Config().PrivacySettings.ShowFullName, a.Config().PrivacySettings.ShowEmailAddress, restrictionsHash) return fmt.Sprintf("%v.%v.%v.%v", a.Srv.Store.User().GetEtagForAllProfiles(), a.Config().PrivacySettings.ShowFullName, a.Config().PrivacySettings.ShowEmailAddress, restrictionsHash)
} }
func (a *App) GetUsersInTeam(options *model.UserGetOptions) ([]*model.User, *model.AppError) { func (a *App) GetUsersInTeam(options *model.UserGetOptions) ([]*model.User, *model.AppError) {

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

@@ -381,15 +381,12 @@ func (us SqlUserStore) GetAllAfter(limit int, afterId string) ([]*model.User, *m
return users, nil return users, nil
} }
func (s SqlUserStore) GetEtagForAllProfiles() store.StoreChannel { func (us SqlUserStore) GetEtagForAllProfiles() string {
return store.Do(func(result *store.StoreResult) { updateAt, err := us.GetReplica().SelectInt("SELECT UpdateAt FROM Users ORDER BY UpdateAt DESC LIMIT 1")
updateAt, err := s.GetReplica().SelectInt("SELECT UpdateAt FROM Users ORDER BY UpdateAt DESC LIMIT 1") if err != nil {
if err != nil { return fmt.Sprintf("%v.%v", model.CurrentVersion, model.GetMillis())
result.Data = fmt.Sprintf("%v.%v", model.CurrentVersion, model.GetMillis()) }
} else { return fmt.Sprintf("%v.%v", model.CurrentVersion, updateAt)
result.Data = fmt.Sprintf("%v.%v", model.CurrentVersion, updateAt)
}
})
} }
func (us SqlUserStore) GetAllProfiles(options *model.UserGetOptions) ([]*model.User, *model.AppError) { func (us SqlUserStore) GetAllProfiles(options *model.UserGetOptions) ([]*model.User, *model.AppError) {

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

@@ -280,7 +280,7 @@ type UserStore interface {
GetByUsername(username string) StoreChannel GetByUsername(username string) StoreChannel
GetForLogin(loginId string, allowSignInWithUsername, allowSignInWithEmail bool) (*model.User, *model.AppError) GetForLogin(loginId string, allowSignInWithUsername, allowSignInWithEmail bool) (*model.User, *model.AppError)
VerifyEmail(userId, email string) (string, *model.AppError) VerifyEmail(userId, email string) (string, *model.AppError)
GetEtagForAllProfiles() StoreChannel GetEtagForAllProfiles() string
GetEtagForProfiles(teamId string) string GetEtagForProfiles(teamId string) string
UpdateFailedPasswordAttempts(userId string, attempts int) StoreChannel UpdateFailedPasswordAttempts(userId string, attempts int) StoreChannel
GetSystemAdminProfiles() (map[string]*model.User, *model.AppError) GetSystemAdminProfiles() (map[string]*model.User, *model.AppError)

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

@@ -373,16 +373,14 @@ func (_m *UserStore) GetChannelGroupUsers(channelID string) ([]*model.User, *mod
} }
// GetEtagForAllProfiles provides a mock function with given fields: // GetEtagForAllProfiles provides a mock function with given fields:
func (_m *UserStore) GetEtagForAllProfiles() store.StoreChannel { func (_m *UserStore) GetEtagForAllProfiles() string {
ret := _m.Called() ret := _m.Called()
var r0 store.StoreChannel var r0 string
if rf, ok := ret.Get(0).(func() store.StoreChannel); ok { if rf, ok := ret.Get(0).(func() string); ok {
r0 = rf() r0 = rf()
} else { } else {
if ret.Get(0) != nil { r0 = ret.Get(0).(string)
r0 = ret.Get(0).(store.StoreChannel)
}
} }
return r0 return r0

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

@@ -457,19 +457,14 @@ func testUserStoreGetAllProfiles(t *testing.T, ss store.Store) {
}) })
t.Run("etag changes for all after user creation", func(t *testing.T) { t.Run("etag changes for all after user creation", func(t *testing.T) {
result := <-ss.User().GetEtagForAllProfiles() etag := ss.User().GetEtagForAllProfiles()
require.Nil(t, result.Err)
etag := result.Data.(string)
uNew := &model.User{} uNew := &model.User{}
uNew.Email = MakeEmail() uNew.Email = MakeEmail()
store.Must(ss.User().Save(uNew)) store.Must(ss.User().Save(uNew))
defer func() { require.Nil(t, ss.User().PermanentDelete(uNew.Id)) }() defer func() { require.Nil(t, ss.User().PermanentDelete(uNew.Id)) }()
result = <-ss.User().GetEtagForAllProfiles() updatedEtag := ss.User().GetEtagForAllProfiles()
require.Nil(t, result.Err)
updatedEtag := result.Data.(string)
require.NotEqual(t, etag, updatedEtag) require.NotEqual(t, etag, updatedEtag)
}) })