diff --git a/app/user.go b/app/user.go index bb484bf0d5..dbfcd05027 100644 --- a/app/user.go +++ b/app/user.go @@ -494,7 +494,7 @@ func (a *App) GetUsersInTeamEtag(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) { diff --git a/store/sqlstore/user_store.go b/store/sqlstore/user_store.go index df2fc96493..c63198bfff 100644 --- a/store/sqlstore/user_store.go +++ b/store/sqlstore/user_store.go @@ -1410,29 +1410,26 @@ func (us SqlUserStore) GetProfilesNotInTeam(teamId string, groupConstrained bool return users, nil } -func (us SqlUserStore) GetEtagForProfilesNotInTeam(teamId string) store.StoreChannel { - return store.Do(func(result *store.StoreResult) { +func (us SqlUserStore) GetEtagForProfilesNotInTeam(teamId string) string { + 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 - 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) - } - }) + return fmt.Sprintf("%v.%v", model.CurrentVersion, etag) } func (us SqlUserStore) ClearAllCustomRoleAssignments() *model.AppError { diff --git a/store/store.go b/store/store.go index 7cc5d923aa..43f6bb8d5f 100644 --- a/store/store.go +++ b/store/store.go @@ -299,7 +299,7 @@ type UserStore interface { AnalyticsGetInactiveUsersCount() (int64, *model.AppError) AnalyticsGetSystemAdminCount() (int64, *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 InferSystemInstallDate() (int64, *model.AppError) GetAllAfter(limit int, afterId string) ([]*model.User, *model.AppError) diff --git a/store/storetest/mocks/UserStore.go b/store/storetest/mocks/UserStore.go index d14c82d92c..b39ada04d6 100644 --- a/store/storetest/mocks/UserStore.go +++ b/store/storetest/mocks/UserStore.go @@ -419,16 +419,14 @@ func (_m *UserStore) GetEtagForProfiles(teamId string) string { } // 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) - var r0 store.StoreChannel - if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok { + var r0 string + if rf, ok := ret.Get(0).(func(string) string); ok { r0 = rf(teamId) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(store.StoreChannel) - } + r0 = ret.Get(0).(string) } return r0 diff --git a/store/storetest/user_store.go b/store/storetest/user_store.go index d8d5df9ee2..326782a781 100644 --- a/store/storetest/user_store.go +++ b/store/storetest/user_store.go @@ -3324,9 +3324,7 @@ func testUserStoreGetProfilesNotInTeam(t *testing.T, ss store.Store) { var etag1, etag2, etag3 string t.Run("etag for profiles not in team 1", func(t *testing.T) { - result := <-ss.User().GetEtagForProfilesNotInTeam(teamId) - require.Nil(t, result.Err) - etag1 = result.Data.(string) + etag1 = ss.User().GetEtagForProfilesNotInTeam(teamId) }) 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) t.Run("etag for profiles not in team 1 after update", func(t *testing.T) { - result := <-ss.User().GetEtagForProfilesNotInTeam(teamId) - require.Nil(t, result.Err) - etag2 = result.Data.(string) + etag2 = ss.User().GetEtagForProfilesNotInTeam(teamId) 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) t.Run("etag for profiles not in team 1 after second update", func(t *testing.T) { - result := <-ss.User().GetEtagForProfilesNotInTeam(teamId) - require.Nil(t, result.Err) - etag3 = result.Data.(string) + etag3 = ss.User().GetEtagForProfilesNotInTeam(teamId) require.NotEqual(t, etag1, 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)) t.Run("etag for profiles not in team 1 after addition to team", func(t *testing.T) { - result := <-ss.User().GetEtagForProfilesNotInTeam(teamId) - require.Nil(t, result.Err) - etag4 := result.Data.(string) + etag4 := ss.User().GetEtagForProfilesNotInTeam(teamId) 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. t.Run("etag for profiles not in team 1 after u3 added to team 2", func(t *testing.T) { t.Skip() - result := <-ss.User().GetEtagForProfilesNotInTeam(teamId) - require.Nil(t, result.Err) - etag4 := result.Data.(string) + etag4 := ss.User().GetEtagForProfilesNotInTeam(teamId) require.Equal(t, etag3, etag4, "etag should not have changed") })