loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request 'fix: keep commit count limit in file history pagination static and not increase with every page' (#6337) from emilylange/fix-file-history-commit-pagination-limit into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6337
Reviewed-by: Gusted <gusted@noreply.codeberg.org>

Gusted 1e7b922e 5b542d6c

+62 -1
+1 -1
modules/git/repo_commit.go
··· 230 230 go func() { 231 231 stderr := strings.Builder{} 232 232 gitCmd := NewCommand(repo.Ctx, "rev-list"). 233 - AddOptionFormat("--max-count=%d", setting.Git.CommitsRangeSize*opts.Page). 233 + AddOptionFormat("--max-count=%d", setting.Git.CommitsRangeSize). 234 234 AddOptionFormat("--skip=%d", skip) 235 235 gitCmd.AddDynamicArguments(opts.Revision) 236 236
+61
modules/git/repo_commit_test.go
··· 7 7 "path/filepath" 8 8 "testing" 9 9 10 + "code.gitea.io/gitea/modules/setting" 11 + "code.gitea.io/gitea/modules/test" 12 + 10 13 "github.com/stretchr/testify/assert" 11 14 "github.com/stretchr/testify/require" 12 15 ) ··· 138 141 require.NoError(t, err) 139 142 assert.EqualValues(t, lTagCommitID, lTag.ID.String()) 140 143 } 144 + 145 + func TestCommitsByRange(t *testing.T) { 146 + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") 147 + bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path) 148 + require.NoError(t, err) 149 + defer bareRepo1.Close() 150 + 151 + baseCommit, err := bareRepo1.GetBranchCommit("master") 152 + require.NoError(t, err) 153 + 154 + testCases := []struct { 155 + Page int 156 + ExpectedCommitCount int 157 + }{ 158 + {1, 3}, 159 + {2, 3}, 160 + {3, 1}, 161 + {4, 0}, 162 + } 163 + for _, testCase := range testCases { 164 + commits, err := baseCommit.CommitsByRange(testCase.Page, 3, "") 165 + require.NoError(t, err) 166 + assert.Len(t, commits, testCase.ExpectedCommitCount, "page: %d", testCase.Page) 167 + } 168 + } 169 + 170 + func TestCommitsByFileAndRange(t *testing.T) { 171 + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") 172 + bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path) 173 + require.NoError(t, err) 174 + defer bareRepo1.Close() 175 + defer test.MockVariableValue(&setting.Git.CommitsRangeSize, 2)() 176 + 177 + testCases := []struct { 178 + File string 179 + Page int 180 + ExpectedCommitCount int 181 + }{ 182 + {"file1.txt", 1, 1}, 183 + {"file2.txt", 1, 1}, 184 + {"file*.txt", 1, 2}, 185 + {"foo", 1, 2}, 186 + {"foo", 2, 1}, 187 + {"foo", 3, 0}, 188 + {"f*", 1, 2}, 189 + {"f*", 2, 2}, 190 + {"f*", 3, 1}, 191 + } 192 + for _, testCase := range testCases { 193 + commits, err := bareRepo1.CommitsByFileAndRange(CommitsByFileAndRangeOptions{ 194 + Revision: "master", 195 + File: testCase.File, 196 + Page: testCase.Page, 197 + }) 198 + require.NoError(t, err) 199 + assert.Len(t, commits, testCase.ExpectedCommitCount, "file: '%s', page: %d", testCase.File, testCase.Page) 200 + } 201 + }