1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-27 09:11:53 -05:00
forgejo/models/git
Gergely Nagy dd8d3f5ebe 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>
(cherry picked from commit 0d029ebe6d)
2024-05-01 05:36:50 +00:00
..
TestIterateRepositoryIDsWithLFSMetaObjects Refactor LFS GC functions 2024-04-06 07:41:40 +00:00
branch.go [PORT] gitea#30430: Fix rename branch 500 when the target branch is deleted but exist in database 2024-04-15 15:52:24 +00:00
branch_list.go Fix git_model.FindBranchesByRepoAndBranchName 2024-05-01 05:36:50 +00:00
branch_test.go Fix git_model.FindBranchesByRepoAndBranchName 2024-05-01 05:36:50 +00:00
commit_status.go Move from max( id ) to max( index ) for latest commit statuses (#30076) 2024-03-30 07:17:31 +01:00
commit_status_test.go fix commit_status 2024-03-24 07:11:19 +01:00
lfs.go Refactor LFS GC functions 2024-04-06 07:41:40 +00:00
lfs_lock.go Introduce path Clean/Join helper functions (#23495) 2023-03-21 16:02:49 -04:00
lfs_test.go Refactor LFS GC functions 2024-04-06 07:41:40 +00: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-04-01 19:31:43 +00: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 Implement FSFE REUSE for golang files (#21840) 2022-11-27 18:20:29 +00:00