GH-11085 Migrate Team.GetAllTeamPageListing to Sync by default (#11106)
* GH-11085 Migrate Team.GetAllTeamPageListing to Sync by default * GH-11085 review fixes * GH-11085 rename data to teams * GH-11085 revert i18n changes
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
f934502a56
Коммит
1a57018adf
@@ -639,11 +639,7 @@ func (a *App) GetAllPublicTeams() ([]*model.Team, *model.AppError) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetAllPublicTeamsPage(offset int, limit int) ([]*model.Team, *model.AppError) {
|
func (a *App) GetAllPublicTeamsPage(offset int, limit int) ([]*model.Team, *model.AppError) {
|
||||||
result := <-a.Srv.Store.Team().GetAllTeamPageListing(offset, limit)
|
return a.Srv.Store.Team().GetAllTeamPageListing(offset, limit)
|
||||||
if result.Err != nil {
|
|
||||||
return nil, result.Err
|
|
||||||
}
|
|
||||||
return result.Data.([]*model.Team), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) SearchAllTeams(term string) ([]*model.Team, *model.AppError) {
|
func (a *App) SearchAllTeams(term string) ([]*model.Team, *model.AppError) {
|
||||||
|
|||||||
@@ -436,22 +436,19 @@ func (s SqlTeamStore) GetAllTeamListing() store.StoreChannel {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlTeamStore) GetAllTeamPageListing(offset int, limit int) store.StoreChannel {
|
func (s SqlTeamStore) GetAllTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
query := "SELECT * FROM Teams WHERE AllowOpenInvite = 1 ORDER BY DisplayName LIMIT :Limit OFFSET :Offset"
|
||||||
query := "SELECT * FROM Teams WHERE AllowOpenInvite = 1 ORDER BY DisplayName LIMIT :Limit OFFSET :Offset"
|
|
||||||
|
|
||||||
if s.DriverName() == model.DATABASE_DRIVER_POSTGRES {
|
if s.DriverName() == model.DATABASE_DRIVER_POSTGRES {
|
||||||
query = "SELECT * FROM Teams WHERE AllowOpenInvite = true ORDER BY DisplayName LIMIT :Limit OFFSET :Offset"
|
query = "SELECT * FROM Teams WHERE AllowOpenInvite = true ORDER BY DisplayName LIMIT :Limit OFFSET :Offset"
|
||||||
}
|
}
|
||||||
|
|
||||||
var data []*model.Team
|
var teams []*model.Team
|
||||||
if _, err := s.GetReplica().Select(&data, query, map[string]interface{}{"Offset": offset, "Limit": limit}); err != nil {
|
if _, err := s.GetReplica().Select(&teams, query, map[string]interface{}{"Offset": offset, "Limit": limit}); err != nil {
|
||||||
result.Err = model.NewAppError("SqlTeamStore.GetAllTeamListing", "store.sql_team.get_all_team_listing.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("SqlTeamStore.GetAllTeamListing", "store.sql_team.get_all_team_listing.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
}
|
||||||
}
|
|
||||||
|
|
||||||
result.Data = data
|
return teams, nil
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlTeamStore) PermanentDelete(teamId string) store.StoreChannel {
|
func (s SqlTeamStore) PermanentDelete(teamId string) store.StoreChannel {
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ type TeamStore interface {
|
|||||||
GetAllPrivateTeamListing() StoreChannel
|
GetAllPrivateTeamListing() StoreChannel
|
||||||
GetAllPrivateTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError)
|
GetAllPrivateTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError)
|
||||||
GetAllTeamListing() StoreChannel
|
GetAllTeamListing() StoreChannel
|
||||||
GetAllTeamPageListing(offset int, limit int) StoreChannel
|
GetAllTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError)
|
||||||
GetTeamsByUserId(userId string) StoreChannel
|
GetTeamsByUserId(userId string) StoreChannel
|
||||||
GetByInviteId(inviteId string) (*model.Team, *model.AppError)
|
GetByInviteId(inviteId string) (*model.Team, *model.AppError)
|
||||||
PermanentDelete(teamId string) StoreChannel
|
PermanentDelete(teamId string) StoreChannel
|
||||||
|
|||||||
@@ -236,19 +236,28 @@ func (_m *TeamStore) GetAllTeamListing() store.StoreChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetAllTeamPageListing provides a mock function with given fields: offset, limit
|
// GetAllTeamPageListing provides a mock function with given fields: offset, limit
|
||||||
func (_m *TeamStore) GetAllTeamPageListing(offset int, limit int) store.StoreChannel {
|
func (_m *TeamStore) GetAllTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError) {
|
||||||
ret := _m.Called(offset, limit)
|
ret := _m.Called(offset, limit)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 []*model.Team
|
||||||
if rf, ok := ret.Get(0).(func(int, int) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(int, int) []*model.Team); ok {
|
||||||
r0 = rf(offset, limit)
|
r0 = rf(offset, limit)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
r0 = ret.Get(0).([]*model.Team)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func(int, int) *model.AppError); ok {
|
||||||
|
r1 = rf(offset, limit)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetByInviteId provides a mock function with given fields: inviteId
|
// GetByInviteId provides a mock function with given fields: inviteId
|
||||||
|
|||||||
@@ -536,20 +536,17 @@ func testGetAllTeamPageListing(t *testing.T, ss store.Store) {
|
|||||||
_, err = ss.Team().Save(&o4)
|
_, err = ss.Team().Save(&o4)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
if r1 := <-ss.Team().GetAllTeamPageListing(0, 10); r1.Err != nil {
|
teams, err := ss.Team().GetAllTeamPageListing(0, 10)
|
||||||
t.Fatal(r1.Err)
|
require.Nil(t, err)
|
||||||
} else {
|
|
||||||
teams := r1.Data.([]*model.Team)
|
|
||||||
|
|
||||||
for _, team := range teams {
|
for _, team := range teams {
|
||||||
if !team.AllowOpenInvite {
|
if !team.AllowOpenInvite {
|
||||||
t.Fatal("should have returned team with AllowOpenInvite as true")
|
t.Fatal("should have returned team with AllowOpenInvite as true")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(teams) > 10 {
|
if len(teams) > 10 {
|
||||||
t.Fatal("should have returned max of 10 teams")
|
t.Fatal("should have returned max of 10 teams")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
o5 := model.Team{}
|
o5 := model.Team{}
|
||||||
@@ -561,37 +558,31 @@ func testGetAllTeamPageListing(t *testing.T, ss store.Store) {
|
|||||||
_, err = ss.Team().Save(&o5)
|
_, err = ss.Team().Save(&o5)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
if r1 := <-ss.Team().GetAllTeamPageListing(0, 4); r1.Err != nil {
|
teams, err = ss.Team().GetAllTeamPageListing(0, 4)
|
||||||
t.Fatal(r1.Err)
|
require.Nil(t, err)
|
||||||
} else {
|
|
||||||
teams := r1.Data.([]*model.Team)
|
|
||||||
|
|
||||||
for _, team := range teams {
|
for _, team := range teams {
|
||||||
if !team.AllowOpenInvite {
|
if !team.AllowOpenInvite {
|
||||||
t.Fatal("should have returned team with AllowOpenInvite as true")
|
t.Fatal("should have returned team with AllowOpenInvite as true")
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(teams) > 4 {
|
|
||||||
t.Fatal("should have returned max of 4 teams")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if r1 := <-ss.Team().GetAllTeamPageListing(1, 1); r1.Err != nil {
|
if len(teams) > 4 {
|
||||||
t.Fatal(r1.Err)
|
t.Fatal("should have returned max of 4 teams")
|
||||||
} else {
|
}
|
||||||
teams := r1.Data.([]*model.Team)
|
|
||||||
|
|
||||||
for _, team := range teams {
|
teams, err = ss.Team().GetAllTeamPageListing(1, 1)
|
||||||
if !team.AllowOpenInvite {
|
require.Nil(t, err)
|
||||||
t.Fatal("should have returned team with AllowOpenInvite as true")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(teams) > 1 {
|
for _, team := range teams {
|
||||||
t.Fatal("should have returned max of 1 team")
|
if !team.AllowOpenInvite {
|
||||||
|
t.Fatal("should have returned team with AllowOpenInvite as true")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(teams) > 1 {
|
||||||
|
t.Fatal("should have returned max of 1 team")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testGetAllPrivateTeamListing(t *testing.T, ss store.Store) {
|
func testGetAllPrivateTeamListing(t *testing.T, ss store.Store) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user