forgejo/models/git
Gergely Nagy 0d029ebe6d
Fix git_model.FindBranchesByRepoAndBranchName
When a logged in user with no repositories visits their dashboard, it will
display a search box that lists their own repositories.

This is served by the `repo.SearchRepos` handler, which in turn calls
`commitstatus_service.FindReposLastestCommitStatuses()` with an empty
repo list.

That, in turn, will call `git_model.FindBranchesByRepoAndBranchName()`,
with an empty map. With no map, `FindBranchesByRepoAndBranchName()` ends
up querying the entire `branch` table, because no conditions were set
up.

Armed with a gazillion repo & commit shas, we return to
`FindReposLastestCommitStatuses`, and promptly call
`git_model.GetLatestCommitStatusForPairs`, which constructs a monstrous
query with so many placeholders that the database tells us to go
somewhere else, and flips us off. At least on instances the size of
Codeberg. On smaller instances, it will eventually return, and throw
away all the data, and return an empty set, having performed all this
for naught.

We fix this by short-circuiting `FindBranchesByRepoAndBranchName`, and
returning fast if our inputs are empty.

A test case is included.

Fixes #3521.

Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
2024-05-01 00:34:39 +02:00
..
TestIterateRepositoryIDsWithLFSMetaObjects Refactor LFS GC functions 2024-04-05 16:49:15 +02:00
branch.go [PORT] gitea#30430: Fix rename branch 500 when the target branch is deleted but exist in database 2024-04-15 16:03:09 +02:00
branch_list.go Fix git_model.FindBranchesByRepoAndBranchName 2024-05-01 00:34:39 +02:00
branch_test.go Fix git_model.FindBranchesByRepoAndBranchName 2024-05-01 00:34:39 +02:00
commit_status.go Add commit status summary table to reduce query from commit status table (#30223) 2024-04-16 12:01:20 +02:00
commit_status_summary.go Fix commitstatus summary (#30431) 2024-04-16 12:01:27 +02:00
commit_status_test.go fix commit_status 2024-03-24 07:11:19 +01:00
lfs.go Refactor LFS GC functions 2024-04-05 16:49:15 +02:00
lfs_lock.go chore: use errors.New to replace fmt.Errorf with no parameters will much better (#30621) 2024-04-28 15:39:00 +02:00
lfs_test.go Refactor LFS GC functions 2024-04-05 16:49:15 +02:00
main_test.go make writing main test easier (#27270) 2023-09-28 01:38:53 +00:00
protected_banch_list_test.go Fix branch protection priority (#24045) 2023-04-11 13:22:49 -04:00
protected_branch.go [FEAT] Configure if protected branch rule should apply to admins 2024-03-29 00:21:49 +01:00
protected_branch_list.go Start to migrate from util.OptionalBool to optional.Option[bool] (#29329) 2024-02-26 22:30:26 +01:00
protected_branch_test.go Supports wildcard protected branch (#20825) 2023-01-16 16:00:22 +08:00
protected_tag.go Refactor some legacy code and remove unused code (#28622) 2023-12-28 09:38:59 +00:00
protected_tag_test.go