forgejo/models
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
..
actions Avoid user does not exist error when detecting schedule actions when the commit author is an external user (#30357) (#30409) 2024-04-15 16:36:33 +02:00
activities [Port] gitea#29930: Move notifications to a standalone file 2024-03-28 14:21:42 +01:00
admin Next round of db.DefaultContext refactor (#27089) 2023-09-16 14:39:12 +00:00
asymkey Clean up log messages (#30313) 2024-04-15 16:11:14 +02:00
auth Fix wrong table name (#30557) (#30651) 2024-04-26 14:39:47 +02:00
avatars Replace 10 more gt- classes with tw- (#29945) 2024-03-26 19:04:27 +01:00
db s/Gitea/Forgejo in various log messages and comments 2024-04-22 14:41:17 +00:00
dbfs make writing main test easier (#27270) 2023-09-28 01:38:53 +00:00
fixtures test: webhook fix branch filter tests 2024-04-30 08:17:10 +00:00
forgejo/semver [SEMVER] store SemVer in ForgejoSemVer after a database upgrade 2024-02-05 14:44:33 +01:00
forgejo_migrations Do not update PRs based on events that happened before they existed 2024-04-12 10:41:19 +02:00
git Fix git_model.FindBranchesByRepoAndBranchName 2024-05-01 05:36:50 +00:00
issues Do not update PRs based on events that happened before they existed 2024-04-12 10:41:19 +02:00
migrations Fix wrong table name (#30557) (#30651) 2024-04-26 14:39:47 +02:00
organization Check the token's owner and repository when registering a runner (#30406) 2024-04-16 11:43:08 +02:00
packages Fix package list performance (#30520) (#30616) 2024-04-21 18:19:06 +02:00
perm Users with read permission of pull requests can be assigned too (#27263) 2024-02-26 22:30:27 +01:00
project Fix migration v292 (#30153) 2024-03-30 07:17:32 +01:00
pull [GITEA] GetScheduledMergeByPullID may involve a system user 2024-02-05 16:09:41 +01:00
repo Clean up log messages (#30313) 2024-04-15 16:11:14 +02:00
secret Make runs-on support variable expression (#29468) 2024-03-11 23:36:59 +07:00
shared/types Refactor locale&string&template related code (#29165) 2024-02-16 15:20:52 +01:00
system Refactor deletion (#28610) 2023-12-25 21:25:29 +01:00
unit Add a direct link from repo header to unit settings 2024-02-13 22:42:09 +01:00
unittest [Windows] prevent ? in testdata path 2024-03-15 13:15:46 +01:00
user [v7.0/forgejo] Add optional pronoun field in user settings (#3076) 2024-04-06 13:23:43 +00:00
webhook webhook: add admin-hooks tests 2024-04-09 21:57:34 +00:00
error.go Add merge style fast-forward-only (#28954) 2024-02-14 17:19:19 +01:00
fixture_generation.go Replace more db.DefaultContext (#27628) 2023-10-15 17:46:06 +02:00
fixture_test.go Replace more db.DefaultContext (#27628) 2023-10-15 17:46:06 +02:00
main_test.go make writing main test easier (#27270) 2023-09-28 01:38:53 +00:00
org.go Refactor deletion (#28610) 2023-12-25 21:25:29 +01:00
org_team.go Remove GetByBean method because sometimes it's danger when query condition parameter is zero and also introduce new generic methods (#28220) 2023-12-07 15:27:36 +08:00
org_team_test.go Reduce usage of db.DefaultContext (#27073) 2023-09-14 17:09:32 +00:00
org_test.go Replace more db.DefaultContext (#27628) 2023-10-15 17:46:06 +02:00
repo.go Refactor deletion (#28610) 2023-12-25 21:25:29 +01:00
repo_test.go Penultimate round of db.DefaultContext refactor (#27414) 2023-10-11 04:24:07 +00:00
repo_transfer.go [MODERATION] User blocking 2024-02-05 15:56:45 +01:00
repo_transfer_test.go [MODERATION] User blocking 2024-02-05 15:56:45 +01:00