Skip to content

Commit fa1be75

Browse files
authored
Merge branch 'main' into bugfix/issue-31423
2 parents a34862a + 1328387 commit fa1be75

File tree

22 files changed

+1087
-92
lines changed

22 files changed

+1087
-92
lines changed

assets/go-licenses.json

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

cmd/serv.go

Lines changed: 85 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import (
2020
asymkey_model "code.gitea.io/gitea/models/asymkey"
2121
git_model "code.gitea.io/gitea/models/git"
2222
"code.gitea.io/gitea/models/perm"
23+
"code.gitea.io/gitea/modules/container"
2324
"code.gitea.io/gitea/modules/git"
2425
"code.gitea.io/gitea/modules/json"
26+
"code.gitea.io/gitea/modules/lfstransfer"
2527
"code.gitea.io/gitea/modules/log"
2628
"code.gitea.io/gitea/modules/pprof"
2729
"code.gitea.io/gitea/modules/private"
@@ -36,7 +38,11 @@ import (
3638
)
3739

3840
const (
39-
lfsAuthenticateVerb = "git-lfs-authenticate"
41+
verbUploadPack = "git-upload-pack"
42+
verbUploadArchive = "git-upload-archive"
43+
verbReceivePack = "git-receive-pack"
44+
verbLfsAuthenticate = "git-lfs-authenticate"
45+
verbLfsTransfer = "git-lfs-transfer"
4046
)
4147

4248
// CmdServ represents the available serv sub-command.
@@ -73,12 +79,18 @@ func setup(ctx context.Context, debug bool) {
7379
}
7480

7581
var (
76-
allowedCommands = map[string]perm.AccessMode{
77-
"git-upload-pack": perm.AccessModeRead,
78-
"git-upload-archive": perm.AccessModeRead,
79-
"git-receive-pack": perm.AccessModeWrite,
80-
lfsAuthenticateVerb: perm.AccessModeNone,
81-
}
82+
// keep getAccessMode() in sync
83+
allowedCommands = container.SetOf(
84+
verbUploadPack,
85+
verbUploadArchive,
86+
verbReceivePack,
87+
verbLfsAuthenticate,
88+
verbLfsTransfer,
89+
)
90+
allowedCommandsLfs = container.SetOf(
91+
verbLfsAuthenticate,
92+
verbLfsTransfer,
93+
)
8294
alphaDashDotPattern = regexp.MustCompile(`[^\w-\.]`)
8395
)
8496

@@ -124,6 +136,45 @@ func handleCliResponseExtra(extra private.ResponseExtra) error {
124136
return nil
125137
}
126138

139+
func getAccessMode(verb, lfsVerb string) perm.AccessMode {
140+
switch verb {
141+
case verbUploadPack, verbUploadArchive:
142+
return perm.AccessModeRead
143+
case verbReceivePack:
144+
return perm.AccessModeWrite
145+
case verbLfsAuthenticate, verbLfsTransfer:
146+
switch lfsVerb {
147+
case "upload":
148+
return perm.AccessModeWrite
149+
case "download":
150+
return perm.AccessModeRead
151+
}
152+
}
153+
// should be unreachable
154+
return perm.AccessModeNone
155+
}
156+
157+
func getLFSAuthToken(ctx context.Context, lfsVerb string, results *private.ServCommandResults) (string, error) {
158+
now := time.Now()
159+
claims := lfs.Claims{
160+
RegisteredClaims: jwt.RegisteredClaims{
161+
ExpiresAt: jwt.NewNumericDate(now.Add(setting.LFS.HTTPAuthExpiry)),
162+
NotBefore: jwt.NewNumericDate(now),
163+
},
164+
RepoID: results.RepoID,
165+
Op: lfsVerb,
166+
UserID: results.UserID,
167+
}
168+
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
169+
170+
// Sign and get the complete encoded token as a string using the secret
171+
tokenString, err := token.SignedString(setting.LFS.JWTSecretBytes)
172+
if err != nil {
173+
return "", fail(ctx, "Failed to sign JWT Token", "Failed to sign JWT token: %v", err)
174+
}
175+
return fmt.Sprintf("Bearer %s", tokenString), nil
176+
}
177+
127178
func runServ(c *cli.Context) error {
128179
ctx, cancel := installSignals()
129180
defer cancel()
@@ -198,15 +249,6 @@ func runServ(c *cli.Context) error {
198249
repoPath := strings.TrimPrefix(words[1], "/")
199250

200251
var lfsVerb string
201-
if verb == lfsAuthenticateVerb {
202-
if !setting.LFS.StartServer {
203-
return fail(ctx, "Unknown git command", "LFS authentication request over SSH denied, LFS support is disabled")
204-
}
205-
206-
if len(words) > 2 {
207-
lfsVerb = words[2]
208-
}
209-
}
210252

211253
rr := strings.SplitN(repoPath, "/", 2)
212254
if len(rr) != 2 {
@@ -243,53 +285,52 @@ func runServ(c *cli.Context) error {
243285
}()
244286
}
245287

246-
requestedMode, has := allowedCommands[verb]
247-
if !has {
288+
if allowedCommands.Contains(verb) {
289+
if allowedCommandsLfs.Contains(verb) {
290+
if !setting.LFS.StartServer {
291+
return fail(ctx, "Unknown git command", "LFS authentication request over SSH denied, LFS support is disabled")
292+
}
293+
if verb == verbLfsTransfer && !setting.LFS.AllowPureSSH {
294+
return fail(ctx, "Unknown git command", "LFS SSH transfer connection denied, pure SSH protocol is disabled")
295+
}
296+
if len(words) > 2 {
297+
lfsVerb = words[2]
298+
}
299+
}
300+
} else {
248301
return fail(ctx, "Unknown git command", "Unknown git command %s", verb)
249302
}
250303

251-
if verb == lfsAuthenticateVerb {
252-
if lfsVerb == "upload" {
253-
requestedMode = perm.AccessModeWrite
254-
} else if lfsVerb == "download" {
255-
requestedMode = perm.AccessModeRead
256-
} else {
257-
return fail(ctx, "Unknown LFS verb", "Unknown lfs verb %s", lfsVerb)
258-
}
259-
}
304+
requestedMode := getAccessMode(verb, lfsVerb)
260305

261306
results, extra := private.ServCommand(ctx, keyID, username, reponame, requestedMode, verb, lfsVerb)
262307
if extra.HasError() {
263308
return fail(ctx, extra.UserMsg, "ServCommand failed: %s", extra.Error)
264309
}
265310

311+
// LFS SSH protocol
312+
if verb == verbLfsTransfer {
313+
token, err := getLFSAuthToken(ctx, lfsVerb, results)
314+
if err != nil {
315+
return err
316+
}
317+
return lfstransfer.Main(ctx, repoPath, lfsVerb, token)
318+
}
319+
266320
// LFS token authentication
267-
if verb == lfsAuthenticateVerb {
321+
if verb == verbLfsAuthenticate {
268322
url := fmt.Sprintf("%s%s/%s.git/info/lfs", setting.AppURL, url.PathEscape(results.OwnerName), url.PathEscape(results.RepoName))
269323

270-
now := time.Now()
271-
claims := lfs.Claims{
272-
RegisteredClaims: jwt.RegisteredClaims{
273-
ExpiresAt: jwt.NewNumericDate(now.Add(setting.LFS.HTTPAuthExpiry)),
274-
NotBefore: jwt.NewNumericDate(now),
275-
},
276-
RepoID: results.RepoID,
277-
Op: lfsVerb,
278-
UserID: results.UserID,
279-
}
280-
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
281-
282-
// Sign and get the complete encoded token as a string using the secret
283-
tokenString, err := token.SignedString(setting.LFS.JWTSecretBytes)
324+
token, err := getLFSAuthToken(ctx, lfsVerb, results)
284325
if err != nil {
285-
return fail(ctx, "Failed to sign JWT Token", "Failed to sign JWT token: %v", err)
326+
return err
286327
}
287328

288329
tokenAuthentication := &git_model.LFSTokenResponse{
289330
Header: make(map[string]string),
290331
Href: url,
291332
}
292-
tokenAuthentication.Header["Authorization"] = fmt.Sprintf("Bearer %s", tokenString)
333+
tokenAuthentication.Header["Authorization"] = token
293334

294335
enc := json.NewEncoder(os.Stdout)
295336
err = enc.Encode(tokenAuthentication)

custom/conf/app.example.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ RUN_USER = ; git
306306
;; Enables git-lfs support. true or false, default is false.
307307
;LFS_START_SERVER = false
308308
;;
309+
;; Enables git-lfs SSH protocol support. true or false, default is false.
310+
;LFS_ALLOW_PURE_SSH = false
309311
;;
310312
;; LFS authentication secret, change this yourself
311313
;LFS_JWT_SECRET =

go.mod

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ require (
3535
github.com/blevesearch/bleve/v2 v2.4.2
3636
github.com/buildkite/terminal-to-html/v3 v3.12.1
3737
github.com/caddyserver/certmagic v0.21.3
38+
github.com/charmbracelet/git-lfs-transfer v0.2.0
3839
github.com/chi-middleware/proxy v1.1.1
3940
github.com/dimiro1/reply v0.0.0-20200315094148-d0136a4c9e21
4041
github.com/djherbis/buffer v1.2.0
@@ -90,7 +91,7 @@ require (
9091
github.com/mholt/archiver/v3 v3.5.1
9192
github.com/microcosm-cc/bluemonday v1.0.26
9293
github.com/microsoft/go-mssqldb v1.7.2
93-
github.com/minio/minio-go/v7 v7.0.71
94+
github.com/minio/minio-go/v7 v7.0.77
9495
github.com/msteinert/pam v1.2.0
9596
github.com/nektos/act v0.2.63
9697
github.com/niklasfasching/go-org v1.7.0
@@ -122,7 +123,7 @@ require (
122123
golang.org/x/image v0.18.0
123124
golang.org/x/net v0.28.0
124125
golang.org/x/oauth2 v0.21.0
125-
golang.org/x/sys v0.23.0
126+
golang.org/x/sys v0.24.0
126127
golang.org/x/text v0.17.0
127128
golang.org/x/tools v0.24.0
128129
google.golang.org/grpc v1.62.1
@@ -197,13 +198,15 @@ require (
197198
github.com/fatih/color v1.17.0 // indirect
198199
github.com/felixge/httpsnoop v1.0.4 // indirect
199200
github.com/fxamacker/cbor/v2 v2.6.0 // indirect
201+
github.com/git-lfs/pktline v0.0.0-20230103162542-ca444d533ef1 // indirect
200202
github.com/go-ap/errors v0.0.0-20240304112515-6077fa9c17b0 // indirect
201203
github.com/go-asn1-ber/asn1-ber v1.5.7 // indirect
202204
github.com/go-enry/go-oniguruma v1.2.1 // indirect
203205
github.com/go-faster/city v1.0.1 // indirect
204206
github.com/go-faster/errors v0.7.1 // indirect
205207
github.com/go-fed/httpsig v1.1.1-0.20201223112313-55836744818e // indirect
206208
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
209+
github.com/go-ini/ini v1.67.0 // indirect
207210
github.com/go-openapi/analysis v0.23.0 // indirect
208211
github.com/go-openapi/errors v0.22.0 // indirect
209212
github.com/go-openapi/inflect v0.21.0 // indirect
@@ -278,7 +281,7 @@ require (
278281
github.com/rhysd/actionlint v1.7.1 // indirect
279282
github.com/rivo/uniseg v0.4.7 // indirect
280283
github.com/rogpeppe/go-internal v1.12.0 // indirect
281-
github.com/rs/xid v1.5.0 // indirect
284+
github.com/rs/xid v1.6.0 // indirect
282285
github.com/russross/blackfriday/v2 v2.1.0 // indirect
283286
github.com/sagikazarmark/locafero v0.4.0 // indirect
284287
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
@@ -329,6 +332,8 @@ replace github.com/shurcooL/vfsgen => github.com/lunny/vfsgen v0.0.0-20220105142
329332

330333
replace github.com/nektos/act => gitea.com/gitea/act v0.259.1
331334

335+
replace github.com/charmbracelet/git-lfs-transfer => gitea.com/gitea/git-lfs-transfer v0.2.0
336+
332337
// TODO: This could be removed after https://github.com/mholt/archiver/pull/396 merged
333338
replace github.com/mholt/archiver/v3 => github.com/anchore/archiver/v3 v3.5.2
334339

go.sum

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078 h1:cliQ4H
1818
git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078/go.mod h1:g/V2Hjas6Z1UHUp4yIx6bATpNzJ7DYtD0FG3+xARWxs=
1919
gitea.com/gitea/act v0.259.1 h1:8GG1o/xtUHl3qjn5f0h/2FXrT5ubBn05TJOM5ry+FBw=
2020
gitea.com/gitea/act v0.259.1/go.mod h1:UxZWRYqQG2Yj4+4OqfGWW5a3HELwejyWFQyU7F1jUD8=
21+
gitea.com/gitea/git-lfs-transfer v0.2.0 h1:baHaNoBSRaeq/xKayEXwiDQtlIjps4Ac/Ll4KqLMB40=
22+
gitea.com/gitea/git-lfs-transfer v0.2.0/go.mod h1:UrXUCm3xLQkq15fu7qlXHUMlrhdlXHoi13KH2Dfiits=
2123
gitea.com/go-chi/binding v0.0.0-20240430071103-39a851e106ed h1:EZZBtilMLSZNWtHHcgq2mt6NSGhJSZBuduAlinMEmso=
2224
gitea.com/go-chi/binding v0.0.0-20240430071103-39a851e106ed/go.mod h1:E3i3cgB04dDx0v3CytCgRTTn9Z/9x891aet3r456RVw=
2325
gitea.com/go-chi/cache v0.2.1 h1:bfAPkvXlbcZxPCpcmDVCWoHgiBSBmZN/QosnZvEC0+g=
@@ -291,6 +293,8 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos
291293
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
292294
github.com/fxamacker/cbor/v2 v2.6.0 h1:sU6J2usfADwWlYDAFhZBQ6TnLFBHxgesMrQfQgk1tWA=
293295
github.com/fxamacker/cbor/v2 v2.6.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
296+
github.com/git-lfs/pktline v0.0.0-20230103162542-ca444d533ef1 h1:mtDjlmloH7ytdblogrMz1/8Hqua1y8B4ID+bh3rvod0=
297+
github.com/git-lfs/pktline v0.0.0-20230103162542-ca444d533ef1/go.mod h1:fenKRzpXDjNpsIBhuhUzvjCKlDjKam0boRAenTE0Q6A=
294298
github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE=
295299
github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8=
296300
github.com/glycerine/go-unsnap-stream v0.0.0-20181221182339-f9677308dec2/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE=
@@ -330,6 +334,8 @@ github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMj
330334
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII=
331335
github.com/go-git/go-git/v5 v5.12.0 h1:7Md+ndsjrzZxbddRDZjF14qK+NN56sy6wkqaVrjZtys=
332336
github.com/go-git/go-git/v5 v5.12.0/go.mod h1:FTM9VKtnI2m65hNI/TenDDDnUf2Q9FHnXYjuz9i5OEY=
337+
github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
338+
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
333339
github.com/go-ldap/ldap/v3 v3.4.6 h1:ert95MdbiG7aWo/oPYp9btL3KJlMPKnP58r09rI8T+A=
334340
github.com/go-ldap/ldap/v3 v3.4.6/go.mod h1:IGMQANNtxpsOzj7uUAMjpGBaOVTC4DYyIy8VsTdxmtc=
335341
github.com/go-openapi/analysis v0.23.0 h1:aGday7OWupfMs+LbmLZG4k0MYXIANxcuBTYUC03zFCU=
@@ -603,8 +609,8 @@ github.com/miekg/dns v1.1.61 h1:nLxbwF3XxhwVSm8g9Dghm9MHPaUZuqhPiGL+675ZmEs=
603609
github.com/miekg/dns v1.1.61/go.mod h1:mnAarhS3nWaW+NVP2wTkYVIZyHNJ098SJZUki3eykwQ=
604610
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
605611
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
606-
github.com/minio/minio-go/v7 v7.0.71 h1:No9XfOKTYi6i0GnBj+WZwD8WP5GZfL7n7GOjRqCdAjA=
607-
github.com/minio/minio-go/v7 v7.0.71/go.mod h1:4yBA8v80xGA30cfM3fz0DKYMXunWl/AV/6tWEs9ryzo=
612+
github.com/minio/minio-go/v7 v7.0.77 h1:GaGghJRg9nwDVlNbwYjSDJT1rqltQkBFDsypWX1v3Bw=
613+
github.com/minio/minio-go/v7 v7.0.77/go.mod h1:AVM3IUN6WwKzmwBxVdjzhH8xq+f57JSbbvzqvUzR6eg=
608614
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
609615
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
610616
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
@@ -713,8 +719,8 @@ github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4
713719
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
714720
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
715721
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
716-
github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc=
717-
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
722+
github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU=
723+
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
718724
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
719725
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
720726
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
@@ -969,8 +975,8 @@ golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
969975
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
970976
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
971977
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
972-
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
973-
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
978+
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
979+
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
974980
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
975981
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
976982
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=

models/activities/action.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -452,13 +452,10 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, err
452452

453453
actions := make([]*Action, 0, opts.PageSize)
454454
var count int64
455+
opts.SetDefaultValues()
455456

456457
if opts.Page < 10 { // TODO: why it's 10 but other values? It's an experience value.
457-
sess := db.GetEngine(ctx).Where(cond).
458-
Select("`action`.*"). // this line will avoid select other joined table's columns
459-
Join("INNER", "repository", "`repository`.id = `action`.repo_id")
460-
461-
opts.SetDefaultValues()
458+
sess := db.GetEngine(ctx).Where(cond)
462459
sess = db.SetSessionPagination(sess, &opts)
463460

464461
count, err = sess.Desc("`action`.created_unix").FindAndCount(&actions)
@@ -467,11 +464,7 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, err
467464
}
468465
} else {
469466
// First, only query which IDs are necessary, and only then query all actions to speed up the overall query
470-
sess := db.GetEngine(ctx).Where(cond).
471-
Select("`action`.id").
472-
Join("INNER", "repository", "`repository`.id = `action`.repo_id")
473-
474-
opts.SetDefaultValues()
467+
sess := db.GetEngine(ctx).Where(cond).Select("`action`.id")
475468
sess = db.SetSessionPagination(sess, &opts)
476469

477470
actionIDs := make([]int64, 0, opts.PageSize)
@@ -481,8 +474,7 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, err
481474

482475
count, err = db.GetEngine(ctx).Where(cond).
483476
Table("action").
484-
Cols("`action`.id").
485-
Join("INNER", "repository", "`repository`.id = `action`.repo_id").Count()
477+
Cols("`action`.id").Count()
486478
if err != nil {
487479
return nil, 0, fmt.Errorf("Count: %w", err)
488480
}

models/activities/action_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ func TestNotifyWatchers(t *testing.T) {
228228
}
229229

230230
func TestGetFeedsCorrupted(t *testing.T) {
231+
// Now we will not check for corrupted data in the feeds
232+
// users should run doctor to fix their data
231233
assert.NoError(t, unittest.PrepareTestDatabase())
232234
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
233235
unittest.AssertExistsAndLoadBean(t, &activities_model.Action{
@@ -241,8 +243,8 @@ func TestGetFeedsCorrupted(t *testing.T) {
241243
IncludePrivate: true,
242244
})
243245
assert.NoError(t, err)
244-
assert.Len(t, actions, 0)
245-
assert.Equal(t, int64(0), count)
246+
assert.Len(t, actions, 1)
247+
assert.Equal(t, int64(1), count)
246248
}
247249

248250
func TestConsistencyUpdateAction(t *testing.T) {

modules/indexer/code/bleve/bleve.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ func (b *Indexer) Search(ctx context.Context, opts *internal.SearchOptions) (int
284284
searchRequest.AddFacet("languages", bleve.NewFacetRequest("Language", 10))
285285
}
286286

287+
searchRequest.SortBy([]string{"-_score", "UpdatedAt"})
288+
287289
result, err := b.inner.Indexer.SearchInContext(ctx, searchRequest)
288290
if err != nil {
289291
return 0, nil, nil, err

0 commit comments

Comments
 (0)