Skip to content

Commit 9faf99d

Browse files
committed
Fix bug
1 parent f24dc5e commit 9faf99d

File tree

5 files changed

+30
-21
lines changed

5 files changed

+30
-21
lines changed

models/issues/pull_list_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ func TestPullRequestList_LoadReviewCommentsCounts(t *testing.T) {
3939
reviewComments, err := prs.LoadReviewCommentsCounts(db.DefaultContext)
4040
assert.NoError(t, err)
4141
assert.Len(t, reviewComments, 2)
42-
assert.Equal(t, 1, reviewComments[prs[0].IssueID])
43-
assert.Equal(t, 2, reviewComments[prs[1].IssueID])
42+
for _, pr := range prs {
43+
assert.Equal(t, 1, reviewComments[pr.IssueID])
44+
}
4445
}
4546

4647
func TestPullRequestList_LoadReviews(t *testing.T) {

models/migrations/v1_25/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 The Gitea Authors. All rights reserved.
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
22
// SPDX-License-Identifier: MIT
33

44
package v1_25

models/migrations/v1_25/v321_test.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,17 @@ import (
1414

1515
func Test_AddFileStatusToAttachment(t *testing.T) {
1616
type Attachment struct {
17-
ID int64 `xorm:"pk autoincr"`
18-
UUID string `xorm:"uuid UNIQUE"`
19-
RepoID int64 `xorm:"INDEX"` // this should not be zero
20-
IssueID int64 `xorm:"INDEX"` // maybe zero when creating
21-
ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating
22-
UploaderID int64 `xorm:"INDEX DEFAULT 0"` // Notice: will be zero before this column added
23-
CommentID int64 `xorm:"INDEX"`
24-
Name string
25-
DownloadCount int64 `xorm:"DEFAULT 0"`
26-
Size int64 `xorm:"DEFAULT 0"`
27-
CreatedUnix timeutil.TimeStamp `xorm:"created"`
28-
CustomDownloadURL string `xorm:"-"`
17+
ID int64 `xorm:"pk autoincr"`
18+
UUID string `xorm:"uuid UNIQUE"`
19+
RepoID int64 `xorm:"INDEX"` // this should not be zero
20+
IssueID int64 `xorm:"INDEX"` // maybe zero when creating
21+
ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating
22+
UploaderID int64 `xorm:"INDEX DEFAULT 0"` // Notice: will be zero before this column added
23+
CommentID int64 `xorm:"INDEX"`
24+
Name string
25+
DownloadCount int64 `xorm:"DEFAULT 0"`
26+
Size int64 `xorm:"DEFAULT 0"`
27+
CreatedUnix timeutil.TimeStamp `xorm:"created"`
2928
}
3029

3130
// Prepare and load the testing database

services/attachment/attachment.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,24 +151,31 @@ func cleanAttachments(ctx context.Context, attachmentIDs []int64) []int64 {
151151
// ScanToBeDeletedAttachments scans for attachments that are marked as to be deleted and send to
152152
// clean queue
153153
func ScanToBeDeletedAttachments(ctx context.Context) error {
154-
attachments := make([]*repo_model.Attachment, 0, 10)
154+
attachmentIDs := make([]int64, 0, 100)
155155
lastID := int64(0)
156156
for {
157157
if err := db.GetEngine(ctx).
158+
Select("id").
158159
// use the status and id index to speed up the query
159160
Where("status = ? AND id > ?", db.FileStatusToBeDeleted, lastID).
160161
Asc("id").
161162
Limit(100).
162-
Find(&attachments); err != nil {
163+
Find(&attachmentIDs); err != nil {
163164
return fmt.Errorf("scan to-be-deleted attachments: %w", err)
164165
}
165166

166-
if len(attachments) == 0 {
167+
if len(attachmentIDs) == 0 {
167168
log.Trace("No more attachments to be deleted")
168169
break
169170
}
170-
AddAttachmentsToCleanQueue(ctx, attachments)
171-
lastID = attachments[len(attachments)-1].ID
171+
for _, id := range attachmentIDs {
172+
if err := cleanQueue.Push(id); err != nil {
173+
log.Error("Failed to push attachment ID %d to clean queue: %v", id, err)
174+
}
175+
}
176+
177+
lastID = attachmentIDs[len(attachmentIDs)-1]
178+
attachmentIDs = attachmentIDs[0:0]
172179
}
173180

174181
return nil

services/issue/issue.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,9 @@ func deleteIssue(ctx context.Context, issue *issues_model.Issue, deleteAttachmen
318318
if err := deleteComment(ctx, comment, deleteAttachments); err != nil {
319319
return nil, fmt.Errorf("deleteComment [comment_id: %d]: %w", comment.ID, err)
320320
}
321-
toBeCleanedAttachments = append(toBeCleanedAttachments, comment.Attachments...)
321+
if deleteAttachments {
322+
toBeCleanedAttachments = append(toBeCleanedAttachments, comment.Attachments...)
323+
}
322324
}
323325

324326
if deleteAttachments {

0 commit comments

Comments
 (0)