diff options
Diffstat (limited to 'models/repo.go')
-rw-r--r-- | models/repo.go | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/models/repo.go b/models/repo.go index a858338b18..632f0be713 100644 --- a/models/repo.go +++ b/models/repo.go @@ -316,33 +316,43 @@ func (repo *Repository) DeleteWiki() { } } -// GetAssignees returns all users that have write access of repository. -func (repo *Repository) GetAssignees() (_ []*User, err error) { - if err = repo.GetOwner(); err != nil { +func (repo *Repository) getAssignees(e Engine) (_ []*User, err error) { + if err = repo.getOwner(e); err != nil { return nil, err } accesses := make([]*Access, 0, 10) - if err = x.Where("repo_id=? AND mode>=?", repo.ID, ACCESS_MODE_WRITE).Find(&accesses); err != nil { + if err = e.Where("repo_id = ? AND mode >= ?", repo.ID, ACCESS_MODE_WRITE).Find(&accesses); err != nil { return nil, err } + if len(accesses) == 0 { + return []*User{}, nil + } + + userIDs := make([]int64, len(accesses)) + for i := 0; i < len(accesses); i++ { + userIDs[i] = accesses[i].UserID + } - users := make([]*User, 0, len(accesses)+1) // Just waste 1 unit does not matter. + // Leave a seat for owner itself to append later, but if owner is an organization + // and just waste 1 unit is cheaper than re-allocate memory once. + users := make([]*User, 0, len(userIDs)+1) + if err = e.In("id", userIDs).Find(&users); err != nil { + return nil, err + } if !repo.Owner.IsOrganization() { users = append(users, repo.Owner) } - var u *User - for i := range accesses { - u, err = GetUserByID(accesses[i].UserID) - if err != nil { - return nil, err - } - users = append(users, u) - } return users, nil } +// GetAssignees returns all users that have write access and can be assigned to issues +// of the repository, +func (repo *Repository) GetAssignees() (_ []*User, err error) { + return repo.getAssignees(x) +} + // GetAssigneeByID returns the user that has write access of repository by given ID. func (repo *Repository) GetAssigneeByID(userID int64) (*User, error) { return GetAssigneeByID(repo, userID) @@ -420,6 +430,8 @@ func (repo *Repository) AllowsPulls() bool { return repo.CanEnablePulls() && repo.EnablePulls } +// FIXME: should have a mutex to prevent producing same index for two issues that are created +// closely enough. func (repo *Repository) NextIssueIndex() int64 { return int64(repo.NumIssues+repo.NumPulls) + 1 } |