forgejo/models
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
..
actions Interpolate runs-on with variables when scheduling tasks (#30640) 2024-04-28 15:39:00 +02:00
activities Reduce unnecessary database queries on actions table (#30509) 2024-04-21 12:07:30 +02:00
admin
asymkey Enable more revive linter rules (#30608) 2024-04-28 15:39:00 +02:00
auth Fix wrong table name (#30557) 2024-04-28 15:39:00 +02:00
avatars Replace 10 more gt- classes with tw- (#29945) 2024-03-26 19:04:27 +01:00
db Enable more revive linter rules (#30608) 2024-04-28 15:39:00 +02:00
dbfs
fixtures test: webhook fix branch filter tests 2024-04-30 09:38:35 +02:00
forgejo/semver
forgejo_migrations Drop Gitea-specific columns from two tables 2024-04-26 10:34:06 +02:00
git Fix git_model.FindBranchesByRepoAndBranchName 2024-05-01 00:34:39 +02:00
issues Enable more revive linter rules (#30608) 2024-04-28 15:39:00 +02:00
migrations Rename migration package name for 1.22-rc1 (#30730) 2024-04-28 15:39:01 +02:00
organization Enable more revive linter rules (#30608) 2024-04-28 15:39:00 +02:00
packages Fix package list performance (#30520) 2024-04-21 16:28:16 +02:00
perm
project Enable more revive linter rules (#30608) 2024-04-28 15:39:00 +02:00
pull
repo Enable more revive linter rules (#30608) 2024-04-28 15:39:00 +02:00
secret
shared/types
system
unit
unittest [CHORE] Remove Microsoft SQL Server Support 2024-04-05 23:37:36 +02:00
user Replace deprecated math/rand functions (#30733) 2024-04-28 15:39:02 +02:00
webhook webhook: sourcehut_builds: ask for access_token instead of authorization_header 2024-04-16 08:59:55 +02:00
error.go
fixture_generation.go
fixture_test.go
main_test.go
org.go
org_team.go
org_team_test.go
org_test.go
repo.go
repo_test.go
repo_transfer.go chore: use errors.New to replace fmt.Errorf with no parameters will much better (#30621) 2024-04-28 15:39:00 +02:00
repo_transfer_test.go