Skip to content

Commit 2916af0

Browse files
committed
Merge branch 'main' into rb/reduce-integration-test-overhead
2 parents edebbfa + 9880c13 commit 2916af0

File tree

22 files changed

+245
-118
lines changed

22 files changed

+245
-118
lines changed

.github/workflows/pull-compliance.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
python-version: "3.12"
3838
- uses: actions/setup-node@v4
3939
with:
40-
node-version: 20
40+
node-version: 22
4141
cache: npm
4242
cache-dependency-path: package-lock.json
4343
- run: pip install poetry
@@ -66,7 +66,7 @@ jobs:
6666
- uses: actions/checkout@v4
6767
- uses: actions/setup-node@v4
6868
with:
69-
node-version: 20
69+
node-version: 22
7070
cache: npm
7171
cache-dependency-path: package-lock.json
7272
- run: make deps-frontend
@@ -137,7 +137,7 @@ jobs:
137137
- uses: actions/checkout@v4
138138
- uses: actions/setup-node@v4
139139
with:
140-
node-version: 20
140+
node-version: 22
141141
cache: npm
142142
cache-dependency-path: package-lock.json
143143
- run: make deps-frontend
@@ -186,7 +186,7 @@ jobs:
186186
- uses: actions/checkout@v4
187187
- uses: actions/setup-node@v4
188188
with:
189-
node-version: 20
189+
node-version: 22
190190
cache: npm
191191
cache-dependency-path: package-lock.json
192192
- run: make deps-frontend

.github/workflows/pull-e2e-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
check-latest: true
2424
- uses: actions/setup-node@v4
2525
with:
26-
node-version: 20
26+
node-version: 22
2727
cache: npm
2828
cache-dependency-path: package-lock.json
2929
- run: make deps-frontend frontend deps-backend

.github/workflows/release-nightly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
check-latest: true
2323
- uses: actions/setup-node@v4
2424
with:
25-
node-version: 20
25+
node-version: 22
2626
cache: npm
2727
cache-dependency-path: package-lock.json
2828
- run: make deps-frontend deps-backend

.github/workflows/release-tag-rc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
check-latest: true
2424
- uses: actions/setup-node@v4
2525
with:
26-
node-version: 20
26+
node-version: 22
2727
cache: npm
2828
cache-dependency-path: package-lock.json
2929
- run: make deps-frontend deps-backend

.github/workflows/release-tag-version.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
check-latest: true
2626
- uses: actions/setup-node@v4
2727
with:
28-
node-version: 20
28+
node-version: 22
2929
cache: npm
3030
cache-dependency-path: package-lock.json
3131
- run: make deps-frontend deps-backend

flake.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
gzip
2323

2424
# frontend
25-
nodejs_20
25+
nodejs_22
2626

2727
# linting
2828
python312

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ replace github.com/shurcooL/vfsgen => github.com/lunny/vfsgen v0.0.0-20220105142
330330

331331
replace github.com/nektos/act => gitea.com/gitea/act v0.261.3
332332

333+
// TODO: the only difference is in `PutObject`: the fork doesn't use `NewVerifyingReader(r, sha256.New(), oid, expectedSize)`, need to figure out why
333334
replace github.com/charmbracelet/git-lfs-transfer => gitea.com/gitea/git-lfs-transfer v0.2.0
334335

335336
// TODO: This could be removed after https://github.com/mholt/archiver/pull/396 merged

models/activities/notification.go

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"code.gitea.io/gitea/modules/timeutil"
1919

2020
"xorm.io/builder"
21+
"xorm.io/xorm/schemas"
2122
)
2223

2324
type (
@@ -50,25 +51,64 @@ const (
5051
// Notification represents a notification
5152
type Notification struct {
5253
ID int64 `xorm:"pk autoincr"`
53-
UserID int64 `xorm:"INDEX NOT NULL"`
54-
RepoID int64 `xorm:"INDEX NOT NULL"`
54+
UserID int64 `xorm:"NOT NULL"`
55+
RepoID int64 `xorm:"NOT NULL"`
5556

56-
Status NotificationStatus `xorm:"SMALLINT INDEX NOT NULL"`
57-
Source NotificationSource `xorm:"SMALLINT INDEX NOT NULL"`
57+
Status NotificationStatus `xorm:"SMALLINT NOT NULL"`
58+
Source NotificationSource `xorm:"SMALLINT NOT NULL"`
5859

59-
IssueID int64 `xorm:"INDEX NOT NULL"`
60-
CommitID string `xorm:"INDEX"`
60+
IssueID int64 `xorm:"NOT NULL"`
61+
CommitID string
6162
CommentID int64
6263

63-
UpdatedBy int64 `xorm:"INDEX NOT NULL"`
64+
UpdatedBy int64 `xorm:"NOT NULL"`
6465

6566
Issue *issues_model.Issue `xorm:"-"`
6667
Repository *repo_model.Repository `xorm:"-"`
6768
Comment *issues_model.Comment `xorm:"-"`
6869
User *user_model.User `xorm:"-"`
6970

70-
CreatedUnix timeutil.TimeStamp `xorm:"created INDEX NOT NULL"`
71-
UpdatedUnix timeutil.TimeStamp `xorm:"updated INDEX NOT NULL"`
71+
CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"`
72+
UpdatedUnix timeutil.TimeStamp `xorm:"updated NOT NULL"`
73+
}
74+
75+
// TableIndices implements xorm's TableIndices interface
76+
func (n *Notification) TableIndices() []*schemas.Index {
77+
indices := make([]*schemas.Index, 0, 8)
78+
usuuIndex := schemas.NewIndex("u_s_uu", schemas.IndexType)
79+
usuuIndex.AddColumn("user_id", "status", "updated_unix")
80+
indices = append(indices, usuuIndex)
81+
82+
// Add the individual indices that were previously defined in struct tags
83+
userIDIndex := schemas.NewIndex("idx_notification_user_id", schemas.IndexType)
84+
userIDIndex.AddColumn("user_id")
85+
indices = append(indices, userIDIndex)
86+
87+
repoIDIndex := schemas.NewIndex("idx_notification_repo_id", schemas.IndexType)
88+
repoIDIndex.AddColumn("repo_id")
89+
indices = append(indices, repoIDIndex)
90+
91+
statusIndex := schemas.NewIndex("idx_notification_status", schemas.IndexType)
92+
statusIndex.AddColumn("status")
93+
indices = append(indices, statusIndex)
94+
95+
sourceIndex := schemas.NewIndex("idx_notification_source", schemas.IndexType)
96+
sourceIndex.AddColumn("source")
97+
indices = append(indices, sourceIndex)
98+
99+
issueIDIndex := schemas.NewIndex("idx_notification_issue_id", schemas.IndexType)
100+
issueIDIndex.AddColumn("issue_id")
101+
indices = append(indices, issueIDIndex)
102+
103+
commitIDIndex := schemas.NewIndex("idx_notification_commit_id", schemas.IndexType)
104+
commitIDIndex.AddColumn("commit_id")
105+
indices = append(indices, commitIDIndex)
106+
107+
updatedByIndex := schemas.NewIndex("idx_notification_updated_by", schemas.IndexType)
108+
updatedByIndex.AddColumn("updated_by")
109+
indices = append(indices, updatedByIndex)
110+
111+
return indices
72112
}
73113

74114
func init() {

models/migrations/migrations.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ func prepareMigrationTasks() []*migration {
366366
newMigration(306, "Add BlockAdminMergeOverride to ProtectedBranch", v1_23.AddBlockAdminMergeOverrideBranchProtection),
367367
newMigration(307, "Fix milestone deadline_unix when there is no due date", v1_23.FixMilestoneNoDueDate),
368368
newMigration(308, "Add index(user_id, is_deleted) for action table", v1_23.AddNewIndexForUserDashboard),
369+
newMigration(309, "Improve Notification table indices", v1_23.ImproveNotificationTableIndices),
369370
}
370371
return preparedMigrations
371372
}

models/migrations/v1_23/v309.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_23 //nolint
5+
6+
import (
7+
"code.gitea.io/gitea/modules/timeutil"
8+
9+
"xorm.io/xorm"
10+
"xorm.io/xorm/schemas"
11+
)
12+
13+
type improveNotificationTableIndicesAction struct {
14+
ID int64 `xorm:"pk autoincr"`
15+
UserID int64 `xorm:"NOT NULL"`
16+
RepoID int64 `xorm:"NOT NULL"`
17+
18+
Status uint8 `xorm:"SMALLINT NOT NULL"`
19+
Source uint8 `xorm:"SMALLINT NOT NULL"`
20+
21+
IssueID int64 `xorm:"NOT NULL"`
22+
CommitID string
23+
CommentID int64
24+
25+
UpdatedBy int64 `xorm:"NOT NULL"`
26+
27+
CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"`
28+
UpdatedUnix timeutil.TimeStamp `xorm:"updated NOT NULL"`
29+
}
30+
31+
// TableName sets the name of this table
32+
func (*improveNotificationTableIndicesAction) TableName() string {
33+
return "notification"
34+
}
35+
36+
// TableIndices implements xorm's TableIndices interface
37+
func (*improveNotificationTableIndicesAction) TableIndices() []*schemas.Index {
38+
indices := make([]*schemas.Index, 0, 8)
39+
usuuIndex := schemas.NewIndex("u_s_uu", schemas.IndexType)
40+
usuuIndex.AddColumn("user_id", "status", "updated_unix")
41+
indices = append(indices, usuuIndex)
42+
43+
// Add the individual indices that were previously defined in struct tags
44+
userIDIndex := schemas.NewIndex("idx_notification_user_id", schemas.IndexType)
45+
userIDIndex.AddColumn("user_id")
46+
indices = append(indices, userIDIndex)
47+
48+
repoIDIndex := schemas.NewIndex("idx_notification_repo_id", schemas.IndexType)
49+
repoIDIndex.AddColumn("repo_id")
50+
indices = append(indices, repoIDIndex)
51+
52+
statusIndex := schemas.NewIndex("idx_notification_status", schemas.IndexType)
53+
statusIndex.AddColumn("status")
54+
indices = append(indices, statusIndex)
55+
56+
sourceIndex := schemas.NewIndex("idx_notification_source", schemas.IndexType)
57+
sourceIndex.AddColumn("source")
58+
indices = append(indices, sourceIndex)
59+
60+
issueIDIndex := schemas.NewIndex("idx_notification_issue_id", schemas.IndexType)
61+
issueIDIndex.AddColumn("issue_id")
62+
indices = append(indices, issueIDIndex)
63+
64+
commitIDIndex := schemas.NewIndex("idx_notification_commit_id", schemas.IndexType)
65+
commitIDIndex.AddColumn("commit_id")
66+
indices = append(indices, commitIDIndex)
67+
68+
updatedByIndex := schemas.NewIndex("idx_notification_updated_by", schemas.IndexType)
69+
updatedByIndex.AddColumn("updated_by")
70+
indices = append(indices, updatedByIndex)
71+
72+
return indices
73+
}
74+
75+
func ImproveNotificationTableIndices(x *xorm.Engine) error {
76+
return x.Sync(&improveNotificationTableIndicesAction{})
77+
}

routers/common/lfs.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"code.gitea.io/gitea/services/lfs"
1111
)
1212

13+
const RouterMockPointCommonLFS = "common-lfs"
14+
1315
func AddOwnerRepoGitLFSRoutes(m *web.Router, middlewares ...any) {
1416
// shared by web and internal routers
1517
m.Group("/{username}/{reponame}/info/lfs", func() {
@@ -25,5 +27,5 @@ func AddOwnerRepoGitLFSRoutes(m *web.Router, middlewares ...any) {
2527
m.Post("/{lid}/unlock", lfs.UnLockHandler)
2628
}, lfs.CheckAcceptMediaType)
2729
m.Any("/*", http.NotFound)
28-
}, middlewares...)
30+
}, append([]any{web.RouterMockPoint(RouterMockPointCommonLFS)}, middlewares...)...)
2931
}

routers/private/internal.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import (
2020
chi_middleware "github.com/go-chi/chi/v5/middleware"
2121
)
2222

23-
const RouterMockPointInternalLFS = "internal-lfs"
24-
2523
func authInternal(next http.Handler) http.Handler {
2624
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
2725
if setting.InternalToken == "" {
@@ -87,10 +85,11 @@ func Routes() *web.Router {
8785

8886
r.Group("/repo", func() {
8987
// FIXME: it is not right to use context.Contexter here because all routes here should use PrivateContext
88+
// Fortunately, the LFS handlers are able to handle requests without a complete web context
9089
common.AddOwnerRepoGitLFSRoutes(r, func(ctx *context.PrivateContext) {
9190
webContext := &context.Context{Base: ctx.Base}
9291
ctx.AppendContextValue(context.WebContextKey, webContext)
93-
}, web.RouterMockPoint(RouterMockPointInternalLFS))
92+
})
9493
})
9594

9695
return r

routers/web/auth/oauth2_provider.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ type userInfoResponse struct {
9191
// InfoOAuth manages request for userinfo endpoint
9292
func InfoOAuth(ctx *context.Context) {
9393
if ctx.Doer == nil || ctx.Data["AuthedMethod"] != (&auth_service.OAuth2{}).Name() {
94-
ctx.Resp.Header().Set("WWW-Authenticate", `Bearer realm=""`)
94+
ctx.Resp.Header().Set("WWW-Authenticate", `Bearer realm="Gitea OAuth2"`)
9595
ctx.PlainText(http.StatusUnauthorized, "no valid authorization")
9696
return
9797
}
@@ -136,7 +136,7 @@ func IntrospectOAuth(ctx *context.Context) {
136136
clientIDValid = err == nil && app.ValidateClientSecret([]byte(clientSecret))
137137
}
138138
if !clientIDValid {
139-
ctx.Resp.Header().Set("WWW-Authenticate", `Basic realm=""`)
139+
ctx.Resp.Header().Set("WWW-Authenticate", `Basic realm="Gitea OAuth2"`)
140140
ctx.PlainText(http.StatusUnauthorized, "no valid authorization")
141141
return
142142
}

routers/web/githttp.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,19 @@ import (
1212
"code.gitea.io/gitea/services/context"
1313
)
1414

15-
func requireSignIn(ctx *context.Context) {
16-
if !setting.Service.RequireSignInView {
17-
return
15+
func addOwnerRepoGitHTTPRouters(m *web.Router) {
16+
reqGitSignIn := func(ctx *context.Context) {
17+
if !setting.Service.RequireSignInView {
18+
return
19+
}
20+
// rely on the results of Contexter
21+
if !ctx.IsSigned {
22+
// TODO: support digit auth - which would be Authorization header with digit
23+
ctx.Resp.Header().Set("WWW-Authenticate", `Basic realm="Gitea"`)
24+
ctx.Error(http.StatusUnauthorized)
25+
}
1826
}
19-
20-
// rely on the results of Contexter
21-
if !ctx.IsSigned {
22-
// TODO: support digit auth - which would be Authorization header with digit
23-
ctx.Resp.Header().Set("WWW-Authenticate", `Basic realm="Gitea"`)
24-
ctx.Error(http.StatusUnauthorized)
25-
}
26-
}
27-
28-
func gitHTTPRouters(m *web.Router) {
29-
m.Group("", func() {
27+
m.Group("/{username}/{reponame}", func() {
3028
m.Methods("POST,OPTIONS", "/git-upload-pack", repo.ServiceUploadPack)
3129
m.Methods("POST,OPTIONS", "/git-receive-pack", repo.ServiceReceivePack)
3230
m.Methods("GET,OPTIONS", "/info/refs", repo.GetInfoRefs)
@@ -38,5 +36,5 @@ func gitHTTPRouters(m *web.Router) {
3836
m.Methods("GET,OPTIONS", "/objects/{head:[0-9a-f]{2}}/{hash:[0-9a-f]{38,62}}", repo.GetLooseObject)
3937
m.Methods("GET,OPTIONS", "/objects/pack/pack-{file:[0-9a-f]{40,64}}.pack", repo.GetPackFile)
4038
m.Methods("GET,OPTIONS", "/objects/pack/pack-{file:[0-9a-f]{40,64}}.idx", repo.GetIdxFile)
41-
}, ignSignInAndCsrf, requireSignIn, repo.HTTPGitEnabledHandler, repo.CorsHandler(), context.UserAssignmentWeb())
39+
}, optSignInIgnoreCsrf, reqGitSignIn, repo.HTTPGitEnabledHandler, repo.CorsHandler(), context.UserAssignmentWeb())
4240
}

0 commit comments

Comments
 (0)