Skip to content

Commit 4500686

Browse files
committed
improve
1 parent b5cc5eb commit 4500686

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

routers/common/blockexpensive.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func isRoutePathExpensive(routePattern string) bool {
4444
"/{username}/{reponame}/blame/",
4545
"/{username}/{reponame}/commit/",
4646
"/{username}/{reponame}/commits/",
47+
"/{username}/{reponame}/graph",
4748
"/{username}/{reponame}/media/",
4849
"/{username}/{reponame}/raw/",
4950
"/{username}/{reponame}/src/",
@@ -56,6 +57,9 @@ func isRoutePathExpensive(routePattern string) bool {
5657

5758
// wiki
5859
"/{username}/{reponame}/wiki/",
60+
61+
// activity
62+
"/{username}/{reponame}/activity/",
5963
}
6064
for _, path := range expensivePaths {
6165
if strings.HasPrefix(routePattern, path) {
@@ -69,8 +73,6 @@ func isRoutePathForLongPolling(routePattern string) bool {
6973
return routePattern == "/user/events"
7074
}
7175

72-
// TODO: add some tests
73-
7476
func determineRequestPriority(reqCtx reqctx.RequestContext) (ret struct {
7577
SignIn bool
7678
Expensive bool

routers/common/blockexpensive_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package common
5+
6+
import (
7+
"github.com/stretchr/testify/assert"
8+
"testing"
9+
)
10+
11+
func TestBlockExpensive(t *testing.T) {
12+
cases := []struct {
13+
expensive bool
14+
routePath string
15+
}{
16+
{false, "/user/xxx"},
17+
{false, "/login/xxx"},
18+
{true, "/{username}/{reponame}/archive/xxx"},
19+
{true, "/{username}/{reponame}/graph"},
20+
{true, "/{username}/{reponame}/src/xxx"},
21+
{true, "/{username}/{reponame}/wiki/xxx"},
22+
{true, "/{username}/{reponame}/activity/xxx"},
23+
}
24+
for _, c := range cases {
25+
assert.Equal(t, c.expensive, isRoutePathExpensive(c.routePath), "routePath: %s", c.routePath)
26+
}
27+
28+
assert.True(t, isRoutePathForLongPolling("/user/events"))
29+
}

0 commit comments

Comments
 (0)