From 06ad61aad38f0b452ec2bccb2161f2dd71cdae95 Mon Sep 17 00:00:00 2001 From: Manush Dodunekov Date: Wed, 8 Jan 2020 22:19:00 +0100 Subject: [PATCH] or even better: `map[int64]*userAccess` --- models/access.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/models/access.go b/models/access.go index a11d47794a..97e85206e3 100644 --- a/models/access.go +++ b/models/access.go @@ -176,10 +176,10 @@ type userAccess struct { } // updateUserAccess updates an access map so that user has at least mode -func updateUserAccess(accessMap map[int64]userAccess, user *User, mode AccessMode) { +func updateUserAccess(accessMap map[int64]*userAccess, user *User, mode AccessMode) { ua, ok := accessMap[user.ID] if !ok { - ua = userAccess{User: user, Mode: mode} + ua = &userAccess{User: user, Mode: mode} accessMap[user.ID] = ua } else { ua.Mode = maxAccessMode(ua.Mode, mode) @@ -187,7 +187,7 @@ func updateUserAccess(accessMap map[int64]userAccess, user *User, mode AccessMod } // FIXME: do cross-comparison so reduce deletions and additions to the minimum? -func (repo *Repository) refreshAccesses(e Engine, accessMap map[int64]userAccess) (err error) { +func (repo *Repository) refreshAccesses(e Engine, accessMap map[int64]*userAccess) (err error) { minMode := AccessModeRead if !repo.IsPrivate { minMode = AccessModeWrite @@ -221,7 +221,7 @@ func (repo *Repository) refreshAccesses(e Engine, accessMap map[int64]userAccess } // refreshCollaboratorAccesses retrieves repository collaborations with their access modes. -func (repo *Repository) refreshCollaboratorAccesses(e Engine, accessMap map[int64]userAccess) error { +func (repo *Repository) refreshCollaboratorAccesses(e Engine, accessMap map[int64]*userAccess) error { collaborators, err := repo.getCollaborators(e) if err != nil { return fmt.Errorf("getCollaborations: %v", err) @@ -236,7 +236,7 @@ func (repo *Repository) refreshCollaboratorAccesses(e Engine, accessMap map[int6 // except the team whose ID is given. It is used to assign a team ID when // remove repository from that team. func (repo *Repository) recalculateTeamAccesses(e Engine, ignTeamID int64) (err error) { - accessMap := make(map[int64]userAccess, 20) + accessMap := make(map[int64]*userAccess, 20) if err = repo.getOwner(e); err != nil { return err @@ -330,7 +330,7 @@ func (repo *Repository) recalculateAccesses(e Engine) error { return repo.recalculateTeamAccesses(e, 0) } - accessMap := make(map[int64]userAccess, 20) + accessMap := make(map[int64]*userAccess, 20) if err := repo.refreshCollaboratorAccesses(e, accessMap); err != nil { return fmt.Errorf("refreshCollaboratorAccesses: %v", err) }