Skip to content

Commit 772ad76

Browse files
authored
Fix some slice problems (incorrect slice length) (#19592)
1 parent c8ec226 commit 772ad76

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

models/auth/oauth2.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func deleteOAuth2Application(sess db.Engine, id, userid int64) error {
245245
"oauth2_authorization_code.grant_id = oauth2_grant.id AND oauth2_grant.application_id = ?", id).Find(&codes); err != nil {
246246
return err
247247
}
248-
codeIDs := make([]int64, 0)
248+
codeIDs := make([]int64, 0, len(codes))
249249
for _, grant := range codes {
250250
codeIDs = append(codeIDs, grant.ID)
251251
}

models/repo_activity.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func GetActivityStatsTopAuthors(ctx context.Context, repo *repo_model.Repository
127127
user.Commits += v.Commits
128128
}
129129
}
130-
v := make([]*ActivityAuthorData, 0)
130+
v := make([]*ActivityAuthorData, 0, len(users))
131131
for _, u := range users {
132132
v = append(v, u)
133133
}

models/user/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type UserList []*User //revive:disable-line:exported
1717

1818
// GetUserIDs returns a slice of user's id
1919
func (users UserList) GetUserIDs() []int64 {
20-
userIDs := make([]int64, len(users))
20+
userIDs := make([]int64, 0, len(users))
2121
for _, user := range users {
2222
userIDs = append(userIDs, user.ID) // Considering that user id are unique in the list
2323
}

0 commit comments

Comments
 (0)