-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Use batch database operations instead of one by one to optimze api pulls #32680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5760487
Use batch database operations instead of one by one to optimze api pulls
lunny 28130c2
Fix bug
lunny 8fc0e95
Add test for new added functions
lunny ce50233
Fix tests
lunny 4b3178f
Merge branch 'main' into lunny/pull_requests_api
lunny 73e29dc
Remove unnecessary code
lunny 96aacf8
Merge branch 'main' into lunny/pull_requests_api
lunny 64ad8f6
Fix bug
lunny 6f963d1
Fix bug
lunny d373b77
Merge branch 'main' into lunny/pull_requests_api
lunny 6be703a
Fix lint
lunny 3652c49
Fix test
lunny f06db79
Fix test
lunny 0a3a2f9
Fix test
lunny 35518d0
Fix test
lunny 6388f66
Revert bug fixes in this pull request so that they could be fixed in …
lunny 6838c6f
Merge branch 'main' into lunny/pull_requests_api
lunny 89cd88e
Merge branch 'main' into lunny/pull_requests_api
lunny dc3fb07
revert change
lunny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package issues_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"code.gitea.io/gitea/models/db" | ||
issues_model "code.gitea.io/gitea/models/issues" | ||
"code.gitea.io/gitea/models/unittest" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestPullRequestList_LoadAttributes(t *testing.T) { | ||
assert.NoError(t, unittest.PrepareTestDatabase()) | ||
|
||
prs := []*issues_model.PullRequest{ | ||
unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1}), | ||
unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2}), | ||
} | ||
assert.NoError(t, issues_model.PullRequestList(prs).LoadAttributes(db.DefaultContext)) | ||
for _, pr := range prs { | ||
assert.NotNil(t, pr.Issue) | ||
assert.Equal(t, pr.IssueID, pr.Issue.ID) | ||
} | ||
|
||
assert.NoError(t, issues_model.PullRequestList([]*issues_model.PullRequest{}).LoadAttributes(db.DefaultContext)) | ||
} | ||
|
||
func TestPullRequestList_LoadReviewCommentsCounts(t *testing.T) { | ||
assert.NoError(t, unittest.PrepareTestDatabase()) | ||
|
||
prs := []*issues_model.PullRequest{ | ||
unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1}), | ||
unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2}), | ||
} | ||
reviewComments, err := issues_model.PullRequestList(prs).LoadReviewCommentsCounts(db.DefaultContext) | ||
assert.NoError(t, err) | ||
assert.Len(t, reviewComments, 2) | ||
for _, pr := range prs { | ||
assert.EqualValues(t, reviewComments[pr.IssueID], 1) | ||
} | ||
} | ||
|
||
func TestPullRequestList_LoadReviews(t *testing.T) { | ||
assert.NoError(t, unittest.PrepareTestDatabase()) | ||
|
||
prs := []*issues_model.PullRequest{ | ||
unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1}), | ||
unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2}), | ||
} | ||
reviewList, err := issues_model.PullRequestList(prs).LoadReviews(db.DefaultContext) | ||
assert.NoError(t, err) | ||
// 1, 7, 8, 9, 10, 22 | ||
assert.Len(t, reviewList, 6) | ||
assert.EqualValues(t, 1, reviewList[0].ID) | ||
assert.EqualValues(t, 7, reviewList[1].ID) | ||
assert.EqualValues(t, 8, reviewList[2].ID) | ||
assert.EqualValues(t, 9, reviewList[3].ID) | ||
assert.EqualValues(t, 10, reviewList[4].ID) | ||
assert.EqualValues(t, 22, reviewList[5].ID) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.