summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2024-04-17 09:25:03 +0800
committerGitHub <noreply@github.com>2024-04-17 01:25:03 +0000
commit6f7d70fb3d2624507c3ccd5640f6d1837259c27d (patch)
treeb3e4d2fb19291afa68a8466921997e362e5ac481
parent38147d020de1bc8909e61d65a39ebd184bd296d7 (diff)
downloadgitea-6f7d70fb3d2624507c3ccd5640f6d1837259c27d.tar.gz
gitea-6f7d70fb3d2624507c3ccd5640f6d1837259c27d.zip
Reduce unnecessary database queries on actions table (#30509)
-rw-r--r--models/activities/action_list.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/models/activities/action_list.go b/models/activities/action_list.go
index 6e23b173b5..aafb7f8a26 100644
--- a/models/activities/action_list.go
+++ b/models/activities/action_list.go
@@ -83,6 +83,9 @@ func (actions ActionList) loadRepoOwner(ctx context.Context, userMap map[int64]*
_, alreadyLoaded := userMap[action.Repo.OwnerID]
return action.Repo.OwnerID, !alreadyLoaded
})
+ if len(missingUserIDs) == 0 {
+ return nil
+ }
if err := db.GetEngine(ctx).
In("id", missingUserIDs).
@@ -129,6 +132,9 @@ func (actions ActionList) LoadComments(ctx context.Context) error {
commentIDs = append(commentIDs, action.CommentID)
}
}
+ if len(commentIDs) == 0 {
+ return nil
+ }
commentsMap := make(map[int64]*issues_model.Comment, len(commentIDs))
if err := db.GetEngine(ctx).In("id", commentIDs).Find(&commentsMap); err != nil {