Skip to content

Commit ea65a8c

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: Fix incorrect ctx usage in defer function (go-gitea#27740) Enable followCursor for language stats bar (go-gitea#27713) teams: new View button (go-gitea#27685) fix issues in translation file (go-gitea#27699) Fix an indentation in the Chinese documentation of Act Runner (go-gitea#27730) [skip ci] Updated translations via Crowdin Fix org team endpoint (go-gitea#27721) Improve diff tree spacing (go-gitea#27714) refactor: make db iterate context aware (go-gitea#27710) [FIX] resolve confusing colors in languages stats by insert a gap (go-gitea#27704) Fix sticky diff header background (go-gitea#27697) Replace -1 with GhostUserID (go-gitea#27703) Clean some functions about project issue (go-gitea#27705)
2 parents 8879756 + f3956fc commit ea65a8c

File tree

23 files changed

+368
-115
lines changed

23 files changed

+368
-115
lines changed

docs/content/usage/actions/act-runner.zh-cn.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,12 @@ services:
208208

209209
```yaml
210210
cache:
211-
enabled: true
212-
dir: ""
213-
# 使用步骤 1. 获取的 LAN IP
214-
host: "192.168.8.17"
215-
# 使用步骤 2. 获取的端口号
216-
port: 8088
211+
enabled: true
212+
dir: ""
213+
# 使用步骤 1. 获取的 LAN IP
214+
host: "192.168.8.17"
215+
# 使用步骤 2. 获取的端口号
216+
port: 8088
217217
```
218218

219219
- 4.启动容器时, 将 Cache 端口映射至主机。

models/db/iterate.go

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,27 @@ func Iterate[Bean any](ctx context.Context, cond builder.Cond, f func(ctx contex
1717
batchSize := setting.Database.IterateBufferSize
1818
sess := GetEngine(ctx)
1919
for {
20-
beans := make([]*Bean, 0, batchSize)
21-
if cond != nil {
22-
sess = sess.Where(cond)
23-
}
24-
if err := sess.Limit(batchSize, start).Find(&beans); err != nil {
25-
return err
26-
}
27-
if len(beans) == 0 {
28-
return nil
29-
}
30-
start += len(beans)
31-
32-
for _, bean := range beans {
33-
if err := f(ctx, bean); err != nil {
20+
select {
21+
case <-ctx.Done():
22+
return ctx.Err()
23+
default:
24+
beans := make([]*Bean, 0, batchSize)
25+
if cond != nil {
26+
sess = sess.Where(cond)
27+
}
28+
if err := sess.Limit(batchSize, start).Find(&beans); err != nil {
3429
return err
3530
}
31+
if len(beans) == 0 {
32+
return nil
33+
}
34+
start += len(beans)
35+
36+
for _, bean := range beans {
37+
if err := f(ctx, bean); err != nil {
38+
return err
39+
}
40+
}
3641
}
3742
}
3843
}

models/issues/comment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ func (c *Comment) LoadPoster(ctx context.Context) (err error) {
349349
c.Poster, err = user_model.GetPossibleUserByID(ctx, c.PosterID)
350350
if err != nil {
351351
if user_model.IsErrUserNotExist(err) {
352-
c.PosterID = -1
352+
c.PosterID = user_model.GhostUserID
353353
c.Poster = user_model.NewGhostUser()
354354
} else {
355355
log.Error("getUserByID[%d]: %v", c.ID, err)

models/issues/issue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func (issue *Issue) LoadPoster(ctx context.Context) (err error) {
219219
if issue.Poster == nil && issue.PosterID != 0 {
220220
issue.Poster, err = user_model.GetPossibleUserByID(ctx, issue.PosterID)
221221
if err != nil {
222-
issue.PosterID = -1
222+
issue.PosterID = user_model.GhostUserID
223223
issue.Poster = user_model.NewGhostUser()
224224
if !user_model.IsErrUserNotExist(err) {
225225
return fmt.Errorf("getUserByID.(poster) [%d]: %w", issue.PosterID, err)

models/issues/issue_project.go

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (issue *Issue) ProjectBoardID(ctx context.Context) int64 {
5151
func LoadIssuesFromBoard(ctx context.Context, b *project_model.Board) (IssueList, error) {
5252
issueList := make(IssueList, 0, 10)
5353

54-
if b.ID != 0 {
54+
if b.ID > 0 {
5555
issues, err := Issues(ctx, &IssuesOptions{
5656
ProjectBoardID: b.ID,
5757
ProjectID: b.ProjectID,
@@ -65,7 +65,7 @@ func LoadIssuesFromBoard(ctx context.Context, b *project_model.Board) (IssueList
6565

6666
if b.Default {
6767
issues, err := Issues(ctx, &IssuesOptions{
68-
ProjectBoardID: -1, // Issues without ProjectBoardID
68+
ProjectBoardID: db.NoConditionID,
6969
ProjectID: b.ProjectID,
7070
SortType: "project-column-sorting",
7171
})
@@ -150,30 +150,3 @@ func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *user_model.U
150150
ProjectID: newProjectID,
151151
})
152152
}
153-
154-
// MoveIssueAcrossProjectBoards move a card from one board to another
155-
func MoveIssueAcrossProjectBoards(ctx context.Context, issue *Issue, board *project_model.Board) error {
156-
ctx, committer, err := db.TxContext(ctx)
157-
if err != nil {
158-
return err
159-
}
160-
defer committer.Close()
161-
sess := db.GetEngine(ctx)
162-
163-
var pis project_model.ProjectIssue
164-
has, err := sess.Where("issue_id=?", issue.ID).Get(&pis)
165-
if err != nil {
166-
return err
167-
}
168-
169-
if !has {
170-
return fmt.Errorf("issue has to be added to a project first")
171-
}
172-
173-
pis.ProjectBoardID = board.ID
174-
if _, err := sess.ID(pis.ID).Cols("project_board_id").Update(&pis); err != nil {
175-
return err
176-
}
177-
178-
return committer.Commit()
179-
}

models/issues/issue_search.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,17 @@ func applyProjectCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Sessio
180180
return sess
181181
}
182182

183+
func applyProjectBoardCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
184+
// opts.ProjectBoardID == 0 means all project boards,
185+
// do not need to apply any condition
186+
if opts.ProjectBoardID > 0 {
187+
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": opts.ProjectBoardID}))
188+
} else if opts.ProjectBoardID == db.NoConditionID {
189+
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Neq{"project_board_id": 0}))
190+
}
191+
return sess
192+
}
193+
183194
func applyRepoConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
184195
if len(opts.RepoIDs) == 1 {
185196
opts.RepoCond = builder.Eq{"issue.repo_id": opts.RepoIDs[0]}
@@ -240,13 +251,7 @@ func applyConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
240251

241252
applyProjectCondition(sess, opts)
242253

243-
if opts.ProjectBoardID != 0 {
244-
if opts.ProjectBoardID > 0 {
245-
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": opts.ProjectBoardID}))
246-
} else {
247-
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": 0}))
248-
}
249-
}
254+
applyProjectBoardCondition(sess, opts)
250255

251256
switch opts.IsPull {
252257
case util.OptionalBoolTrue:

models/issues/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ func (pr *PullRequest) LoadAttributes(ctx context.Context) (err error) {
272272
if pr.HasMerged && pr.Merger == nil {
273273
pr.Merger, err = user_model.GetUserByID(ctx, pr.MergerID)
274274
if user_model.IsErrUserNotExist(err) {
275-
pr.MergerID = -1
275+
pr.MergerID = user_model.GhostUserID
276276
pr.Merger = user_model.NewGhostUser()
277277
} else if err != nil {
278278
return fmt.Errorf("getUserByID [%d]: %w", pr.MergerID, err)

models/user/avatar.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ func GenerateRandomAvatar(ctx context.Context, u *User) error {
5858

5959
// AvatarLinkWithSize returns a link to the user's avatar with size. size <= 0 means default size
6060
func (u *User) AvatarLinkWithSize(ctx context.Context, size int) string {
61-
if u.ID == -1 {
62-
// ghost user
61+
if u.IsGhost() {
6362
return avatars.DefaultAvatarLink()
6463
}
6564

models/user/user.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ func GetUserByIDs(ctx context.Context, ids []int64) ([]*User, error) {
933933
// GetPossibleUserByID returns the user if id > 0 or return system usrs if id < 0
934934
func GetPossibleUserByID(ctx context.Context, id int64) (*User, error) {
935935
switch id {
936-
case -1:
936+
case GhostUserID:
937937
return NewGhostUser(), nil
938938
case ActionsUserID:
939939
return NewActionsUser(), nil
@@ -949,7 +949,7 @@ func GetPossibleUserByIDs(ctx context.Context, ids []int64) ([]*User, error) {
949949
uniqueIDs := container.SetOf(ids...)
950950
users := make([]*User, 0, len(ids))
951951
_ = uniqueIDs.Remove(0)
952-
if uniqueIDs.Remove(-1) {
952+
if uniqueIDs.Remove(GhostUserID) {
953953
users = append(users, NewGhostUser())
954954
}
955955
if uniqueIDs.Remove(ActionsUserID) {

models/user/user_system.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ import (
99
"code.gitea.io/gitea/modules/structs"
1010
)
1111

12+
const (
13+
GhostUserID = -1
14+
GhostUserName = "Ghost"
15+
GhostUserLowerName = "ghost"
16+
)
17+
1218
// NewGhostUser creates and returns a fake user for someone has deleted their account.
1319
func NewGhostUser() *User {
1420
return &User{
15-
ID: -1,
16-
Name: "Ghost",
17-
LowerName: "ghost",
21+
ID: GhostUserID,
22+
Name: GhostUserName,
23+
LowerName: GhostUserLowerName,
1824
}
1925
}
2026

@@ -23,13 +29,13 @@ func (u *User) IsGhost() bool {
2329
if u == nil {
2430
return false
2531
}
26-
return u.ID == -1 && u.Name == "Ghost"
32+
return u.ID == GhostUserID && u.Name == GhostUserName
2733
}
2834

2935
// NewReplaceUser creates and returns a fake user for external user
3036
func NewReplaceUser(name string) *User {
3137
return &User{
32-
ID: -1,
38+
ID: 0,
3339
Name: name,
3440
LowerName: strings.ToLower(name),
3541
}

0 commit comments

Comments
 (0)