mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[MM-16574] Migrate "User.GetEtagForProfilesNotInTeam" to Sync by default (#11518)
* [MM-16574] Migrate "User.GetEtagForProfilesNotInTeam" to Sync by default * Update "GetEtagForProfilesNotInTeam" interface
This commit is contained in:
committed by
Jesús Espino
parent
2e48b6ef3f
commit
2149e3dd2f
@@ -494,7 +494,7 @@ func (a *App) GetUsersInTeamEtag(teamId string, restrictionsHash string) string
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetUsersNotInTeamEtag(teamId string, restrictionsHash string) string {
|
func (a *App) GetUsersNotInTeamEtag(teamId string, restrictionsHash string) string {
|
||||||
return fmt.Sprintf("%v.%v.%v.%v", (<-a.Srv.Store.User().GetEtagForProfilesNotInTeam(teamId)).Data.(string), a.Config().PrivacySettings.ShowFullName, a.Config().PrivacySettings.ShowEmailAddress, restrictionsHash)
|
return fmt.Sprintf("%v.%v.%v.%v", a.Srv.Store.User().GetEtagForProfilesNotInTeam(teamId), a.Config().PrivacySettings.ShowFullName, a.Config().PrivacySettings.ShowEmailAddress, restrictionsHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetUsersInChannel(channelId string, offset int, limit int) ([]*model.User, *model.AppError) {
|
func (a *App) GetUsersInChannel(channelId string, offset int, limit int) ([]*model.User, *model.AppError) {
|
||||||
|
|||||||
@@ -1410,29 +1410,26 @@ func (us SqlUserStore) GetProfilesNotInTeam(teamId string, groupConstrained bool
|
|||||||
return users, nil
|
return users, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) GetEtagForProfilesNotInTeam(teamId string) store.StoreChannel {
|
func (us SqlUserStore) GetEtagForProfilesNotInTeam(teamId string) string {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
var querystr string
|
||||||
|
querystr = `
|
||||||
|
SELECT
|
||||||
|
CONCAT(MAX(UpdateAt), '.', COUNT(Id)) as etag
|
||||||
|
FROM
|
||||||
|
Users as u
|
||||||
|
LEFT JOIN TeamMembers tm
|
||||||
|
ON tm.UserId = u.Id
|
||||||
|
AND tm.TeamId = :TeamId
|
||||||
|
AND tm.DeleteAt = 0
|
||||||
|
WHERE
|
||||||
|
tm.UserId IS NULL
|
||||||
|
`
|
||||||
|
etag, err := us.GetReplica().SelectStr(querystr, map[string]interface{}{"TeamId": teamId})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Sprintf("%v.%v", model.CurrentVersion, model.GetMillis())
|
||||||
|
}
|
||||||
|
|
||||||
var querystr string
|
return fmt.Sprintf("%v.%v", model.CurrentVersion, etag)
|
||||||
querystr = `
|
|
||||||
SELECT
|
|
||||||
CONCAT(MAX(UpdateAt), '.', COUNT(Id)) as etag
|
|
||||||
FROM
|
|
||||||
Users as u
|
|
||||||
LEFT JOIN TeamMembers tm
|
|
||||||
ON tm.UserId = u.Id
|
|
||||||
AND tm.TeamId = :TeamId
|
|
||||||
AND tm.DeleteAt = 0
|
|
||||||
WHERE
|
|
||||||
tm.UserId IS NULL
|
|
||||||
`
|
|
||||||
etag, err := us.GetReplica().SelectStr(querystr, map[string]interface{}{"TeamId": teamId})
|
|
||||||
if err != nil {
|
|
||||||
result.Data = fmt.Sprintf("%v.%v", model.CurrentVersion, model.GetMillis())
|
|
||||||
} else {
|
|
||||||
result.Data = fmt.Sprintf("%v.%v", model.CurrentVersion, etag)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) ClearAllCustomRoleAssignments() *model.AppError {
|
func (us SqlUserStore) ClearAllCustomRoleAssignments() *model.AppError {
|
||||||
|
|||||||
@@ -299,7 +299,7 @@ type UserStore interface {
|
|||||||
AnalyticsGetInactiveUsersCount() (int64, *model.AppError)
|
AnalyticsGetInactiveUsersCount() (int64, *model.AppError)
|
||||||
AnalyticsGetSystemAdminCount() (int64, *model.AppError)
|
AnalyticsGetSystemAdminCount() (int64, *model.AppError)
|
||||||
GetProfilesNotInTeam(teamId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
GetProfilesNotInTeam(teamId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
||||||
GetEtagForProfilesNotInTeam(teamId string) StoreChannel
|
GetEtagForProfilesNotInTeam(teamId string) string
|
||||||
ClearAllCustomRoleAssignments() *model.AppError
|
ClearAllCustomRoleAssignments() *model.AppError
|
||||||
InferSystemInstallDate() (int64, *model.AppError)
|
InferSystemInstallDate() (int64, *model.AppError)
|
||||||
GetAllAfter(limit int, afterId string) ([]*model.User, *model.AppError)
|
GetAllAfter(limit int, afterId string) ([]*model.User, *model.AppError)
|
||||||
|
|||||||
@@ -419,16 +419,14 @@ func (_m *UserStore) GetEtagForProfiles(teamId string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetEtagForProfilesNotInTeam provides a mock function with given fields: teamId
|
// GetEtagForProfilesNotInTeam provides a mock function with given fields: teamId
|
||||||
func (_m *UserStore) GetEtagForProfilesNotInTeam(teamId string) store.StoreChannel {
|
func (_m *UserStore) GetEtagForProfilesNotInTeam(teamId string) string {
|
||||||
ret := _m.Called(teamId)
|
ret := _m.Called(teamId)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 string
|
||||||
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string) string); ok {
|
||||||
r0 = rf(teamId)
|
r0 = rf(teamId)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
r0 = ret.Get(0).(string)
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
return r0
|
||||||
|
|||||||
@@ -3324,9 +3324,7 @@ func testUserStoreGetProfilesNotInTeam(t *testing.T, ss store.Store) {
|
|||||||
var etag1, etag2, etag3 string
|
var etag1, etag2, etag3 string
|
||||||
|
|
||||||
t.Run("etag for profiles not in team 1", func(t *testing.T) {
|
t.Run("etag for profiles not in team 1", func(t *testing.T) {
|
||||||
result := <-ss.User().GetEtagForProfilesNotInTeam(teamId)
|
etag1 = ss.User().GetEtagForProfilesNotInTeam(teamId)
|
||||||
require.Nil(t, result.Err)
|
|
||||||
etag1 = result.Data.(string)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("get not in team 1, offset 0, limit 100000", func(t *testing.T) {
|
t.Run("get not in team 1, offset 0, limit 100000", func(t *testing.T) {
|
||||||
@@ -3364,9 +3362,7 @@ func testUserStoreGetProfilesNotInTeam(t *testing.T, ss store.Store) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
t.Run("etag for profiles not in team 1 after update", func(t *testing.T) {
|
t.Run("etag for profiles not in team 1 after update", func(t *testing.T) {
|
||||||
result := <-ss.User().GetEtagForProfilesNotInTeam(teamId)
|
etag2 = ss.User().GetEtagForProfilesNotInTeam(teamId)
|
||||||
require.Nil(t, result.Err)
|
|
||||||
etag2 = result.Data.(string)
|
|
||||||
require.NotEqual(t, etag2, etag1, "etag should have changed")
|
require.NotEqual(t, etag2, etag1, "etag should have changed")
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -3389,9 +3385,7 @@ func testUserStoreGetProfilesNotInTeam(t *testing.T, ss store.Store) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
t.Run("etag for profiles not in team 1 after second update", func(t *testing.T) {
|
t.Run("etag for profiles not in team 1 after second update", func(t *testing.T) {
|
||||||
result := <-ss.User().GetEtagForProfilesNotInTeam(teamId)
|
etag3 = ss.User().GetEtagForProfilesNotInTeam(teamId)
|
||||||
require.Nil(t, result.Err)
|
|
||||||
etag3 = result.Data.(string)
|
|
||||||
require.NotEqual(t, etag1, etag3, "etag should have changed")
|
require.NotEqual(t, etag1, etag3, "etag should have changed")
|
||||||
require.NotEqual(t, etag2, etag3, "etag should have changed")
|
require.NotEqual(t, etag2, etag3, "etag should have changed")
|
||||||
})
|
})
|
||||||
@@ -3417,9 +3411,7 @@ func testUserStoreGetProfilesNotInTeam(t *testing.T, ss store.Store) {
|
|||||||
store.Must(ss.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: u4.Id}, -1))
|
store.Must(ss.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: u4.Id}, -1))
|
||||||
|
|
||||||
t.Run("etag for profiles not in team 1 after addition to team", func(t *testing.T) {
|
t.Run("etag for profiles not in team 1 after addition to team", func(t *testing.T) {
|
||||||
result := <-ss.User().GetEtagForProfilesNotInTeam(teamId)
|
etag4 := ss.User().GetEtagForProfilesNotInTeam(teamId)
|
||||||
require.Nil(t, result.Err)
|
|
||||||
etag4 := result.Data.(string)
|
|
||||||
require.Equal(t, etag3, etag4, "etag should not have changed")
|
require.Equal(t, etag3, etag4, "etag should not have changed")
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -3435,9 +3427,7 @@ func testUserStoreGetProfilesNotInTeam(t *testing.T, ss store.Store) {
|
|||||||
// solution, which only uses UserIds, would solve this issue.
|
// solution, which only uses UserIds, would solve this issue.
|
||||||
t.Run("etag for profiles not in team 1 after u3 added to team 2", func(t *testing.T) {
|
t.Run("etag for profiles not in team 1 after u3 added to team 2", func(t *testing.T) {
|
||||||
t.Skip()
|
t.Skip()
|
||||||
result := <-ss.User().GetEtagForProfilesNotInTeam(teamId)
|
etag4 := ss.User().GetEtagForProfilesNotInTeam(teamId)
|
||||||
require.Nil(t, result.Err)
|
|
||||||
etag4 := result.Data.(string)
|
|
||||||
require.Equal(t, etag3, etag4, "etag should not have changed")
|
require.Equal(t, etag3, etag4, "etag should not have changed")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user