1
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-05-18 00:49:09 -04:00

chore: fix duplicate to satisfy

This commit is contained in:
Jason Song 2022-11-26 20:51:45 +08:00
parent 0bd9553219
commit 7854178da4
No known key found for this signature in database
GPG Key ID: 8402EEEE4511A8B5
2 changed files with 26 additions and 32 deletions

View File

@ -30,22 +30,9 @@ func (comments CommentList) LoadPosters(ctx context.Context) error {
return nil
}
posterIDs := comments.getPosterIDs()
posterMaps := make(map[int64]*user_model.User, len(posterIDs))
left := len(posterIDs)
for left > 0 {
limit := db.DefaultMaxInSize
if left < limit {
limit = left
}
err := db.GetEngine(ctx).
In("id", posterIDs[:limit]).
Find(&posterMaps)
if err != nil {
return err
}
left -= limit
posterIDs = posterIDs[limit:]
posterMaps, err := getPosters(ctx, comments.getPosterIDs())
if err != nil {
return err
}
for _, comment := range comments {

View File

@ -87,22 +87,9 @@ func (issues IssueList) loadPosters(ctx context.Context) error {
return nil
}
posterIDs := issues.getPosterIDs()
posterMaps := make(map[int64]*user_model.User, len(posterIDs))
left := len(posterIDs)
for left > 0 {
limit := db.DefaultMaxInSize
if left < limit {
limit = left
}
err := db.GetEngine(ctx).
In("id", posterIDs[:limit]).
Find(&posterMaps)
if err != nil {
return err
}
left -= limit
posterIDs = posterIDs[limit:]
posterMaps, err := getPosters(ctx, issues.getPosterIDs())
if err != nil {
return err
}
for _, issue := range issues {
@ -120,6 +107,26 @@ func (issues IssueList) loadPosters(ctx context.Context) error {
return nil
}
func getPosters(ctx context.Context, posterIDs []int64) (map[int64]*user_model.User, error) {
posterMaps := make(map[int64]*user_model.User, len(posterIDs))
left := len(posterIDs)
for left > 0 {
limit := db.DefaultMaxInSize
if left < limit {
limit = left
}
err := db.GetEngine(ctx).
In("id", posterIDs[:limit]).
Find(&posterMaps)
if err != nil {
return nil, err
}
left -= limit
posterIDs = posterIDs[limit:]
}
return posterMaps, nil
}
func (issues IssueList) getIssueIDs() []int64 {
ids := make([]int64, 0, len(issues))
for _, issue := range issues {