Skip to content

Commit 4761bf2

Browse files
committed
Fix bug when updating actions numbers
1 parent aa21dc3 commit 4761bf2

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

models/asymkey/gpg_key_verify.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func VerifyGPGKey(ctx context.Context, ownerID int64, keyID, token, signature st
7878
}
7979

8080
key.Verified = true
81-
if _, err := db.GetEngine(ctx).ID(key.ID).SetExpr("verified", true).Update(new(GPGKey)); err != nil {
81+
if _, err := db.GetEngine(ctx).ID(key.ID).Cols("verified").Update(key); err != nil {
8282
return "", err
8383
}
8484

models/issues/label.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -495,19 +495,23 @@ func CountLabelsByOrgID(ctx context.Context, orgID int64) (int64, error) {
495495
}
496496

497497
func updateLabelCols(ctx context.Context, l *Label, cols ...string) error {
498-
_, err := db.GetEngine(ctx).ID(l.ID).
499-
SetExpr("num_issues",
498+
sess := db.GetEngine(ctx).ID(l.ID)
499+
if slices.Contains(cols, "num_issues") {
500+
sess.SetExpr("num_issues",
500501
builder.Select("count(*)").From("issue_label").
501502
Where(builder.Eq{"label_id": l.ID}),
502-
).
503-
SetExpr("num_closed_issues",
503+
)
504+
}
505+
if slices.Contains(cols, "num_closed_issues") {
506+
sess.SetExpr("num_closed_issues",
504507
builder.Select("count(*)").From("issue_label").
505508
InnerJoin("issue", "issue_label.issue_id = issue.id").
506509
Where(builder.Eq{
507510
"issue_label.label_id": l.ID,
508511
"issue.is_closed": true,
509512
}),
510-
).
511-
Cols(cols...).Update(l)
513+
)
514+
}
515+
_, err := sess.Cols(cols...).Update(l)
512516
return err
513517
}

models/issues/milestone.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ func updateMilestone(ctx context.Context, m *Milestone) error {
181181
func UpdateMilestoneCounters(ctx context.Context, id int64) error {
182182
e := db.GetEngine(ctx)
183183
_, err := e.ID(id).
184+
Cols("num_issues", "num_closed_issues").
184185
SetExpr("num_issues", builder.Select("count(*)").From("issue").Where(
185186
builder.Eq{"milestone_id": id},
186187
)).

models/migrations/v1_18/v229.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func UpdateOpenMilestoneCounts(x *xorm.Engine) error {
2121

2222
for _, id := range openMilestoneIDs {
2323
_, err := x.ID(id).
24+
Cols("num_issues", "num_closed_issues").
2425
SetExpr("num_issues", builder.Select("count(*)").From("issue").Where(
2526
builder.Eq{"milestone_id": id},
2627
)).

models/repo/topic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func RemoveTopicsFromRepo(ctx context.Context, repoID int64) error {
159159
builder.In("id",
160160
builder.Select("topic_id").From("repo_topic").Where(builder.Eq{"repo_id": repoID}),
161161
),
162-
).Cols("repo_count").SetExpr("repo_count", "repo_count-1").Update(&Topic{})
162+
).Decr("repo_count").Update(&Topic{})
163163
if err != nil {
164164
return err
165165
}

0 commit comments

Comments
 (0)