Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: user permission list problem #372

Merged
merged 1 commit into from
Feb 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions internal/pkg/service/permission/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/douyu/juno/pkg/model/db"
"github.com/douyu/juno/pkg/model/view"
"github.com/douyu/jupiter/pkg/store/gorm"
"golang.org/x/sync/errgroup"
)

var (
Expand All @@ -25,7 +24,7 @@ func initUser(db *gorm.DB) {

func (u *user) List(param view.ReqListUser) (resp view.RespListUser, err error) {
var users []db.User
var eg errgroup.Group

var limit = param.PageSize
var offset = param.Page * param.PageSize
var total int64
Expand All @@ -45,20 +44,15 @@ func (u *user) List(param view.ReqListUser) (resp view.RespListUser, err error)
query = query.Where("username like ? or nickname like ?", searchText, searchText)
}

eg.Go(func() error {
return query.Preload("Groups").
Limit(limit).Offset(offset).Find(&users).Error
})

eg.Go(func() error {
return query.Model(&db.User{}).Count(&total).Error
})

err = eg.Wait()
err = query.Preload("Groups").
Limit(limit).Offset(offset).Find(&users).Error
if err != nil {
return
}
err = query.Table("user").Count(&total).Error
if err != nil {
return
}

resp.Pagination.PageSize = int(limit)
resp.Pagination.Current = int(param.Page)
resp.Pagination.Total = total
Expand Down