From 1dd83dbb917d55bd253001646d6743f247a4d98b Mon Sep 17 00:00:00 2001 From: Matthew Walowski Date: Mon, 8 May 2023 18:06:05 -0700 Subject: Filters for GetAllCommits (#24568) The `GetAllCommits` endpoint can be pretty slow, especially in repos with a lot of commits. The issue is that it spends a lot of time calculating information that may not be useful/needed by the user. The `stat` param was previously added in #21337 to address this, by allowing the user to disable the calculating stats for each commit. But this has two issues: 1. The name `stat` is rather misleading, because disabling `stat` disables the Stat **and** Files. This should be separated out into two different params, because getting a list of affected files is much less expensive than calculating the stats 2. There's still other costly information provided that the user may not need, such as `Verification` This PR, adds two parameters to the endpoint, `files` and `verification` to allow the user to explicitly disable this information when listing commits. The default behavior is true. --- tests/integration/api_repo_git_commits_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests/integration') diff --git a/tests/integration/api_repo_git_commits_test.go b/tests/integration/api_repo_git_commits_test.go index d9c3d7b952..90048a5496 100644 --- a/tests/integration/api_repo_git_commits_test.go +++ b/tests/integration/api_repo_git_commits_test.go @@ -135,6 +135,27 @@ func TestAPIReposGitCommitListDifferentBranch(t *testing.T) { compareCommitFiles(t, []string{"readme.md"}, apiData[0].Files) } +func TestAPIReposGitCommitListWithoutSelectFields(t *testing.T) { + defer tests.PrepareTestEnv(t)() + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) + // Login as User2. + session := loginUser(t, user.Name) + token := getTokenForLoggedInUser(t, session) + + // Test getting commits without files, verification, and stats + req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo16/commits?token="+token+"&sha=good-sign&stat=false&files=false&verification=false", user.Name) + resp := MakeRequest(t, req, http.StatusOK) + + var apiData []api.Commit + DecodeJSON(t, resp, &apiData) + + assert.Len(t, apiData, 1) + assert.Equal(t, "f27c2b2b03dcab38beaf89b0ab4ff61f6de63441", apiData[0].CommitMeta.SHA) + assert.Equal(t, (*api.CommitStats)(nil), apiData[0].Stats) + assert.Equal(t, (*api.PayloadCommitVerification)(nil), apiData[0].RepoCommit.Verification) + assert.Equal(t, ([]*api.CommitAffectedFiles)(nil), apiData[0].Files) +} + func TestDownloadCommitDiffOrPatch(t *testing.T) { defer tests.PrepareTestEnv(t)() user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) -- cgit v1.2.3