This commit is contained in:
Lunny Xiao 2025-07-20 13:14:29 -07:00
parent f24dc5e658
commit 9faf99d8ed
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
5 changed files with 30 additions and 21 deletions

View File

@ -39,8 +39,9 @@ func TestPullRequestList_LoadReviewCommentsCounts(t *testing.T) {
reviewComments, err := prs.LoadReviewCommentsCounts(db.DefaultContext)
assert.NoError(t, err)
assert.Len(t, reviewComments, 2)
assert.Equal(t, 1, reviewComments[prs[0].IssueID])
assert.Equal(t, 2, reviewComments[prs[1].IssueID])
for _, pr := range prs {
assert.Equal(t, 1, reviewComments[pr.IssueID])
}
}
func TestPullRequestList_LoadReviews(t *testing.T) {

View File

@ -1,4 +1,4 @@
// Copyright 2024 The Gitea Authors. All rights reserved.
// Copyright 2025 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package v1_25

View File

@ -14,18 +14,17 @@ import (
func Test_AddFileStatusToAttachment(t *testing.T) {
type Attachment struct {
ID int64 `xorm:"pk autoincr"`
UUID string `xorm:"uuid UNIQUE"`
RepoID int64 `xorm:"INDEX"` // this should not be zero
IssueID int64 `xorm:"INDEX"` // maybe zero when creating
ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating
UploaderID int64 `xorm:"INDEX DEFAULT 0"` // Notice: will be zero before this column added
CommentID int64 `xorm:"INDEX"`
Name string
DownloadCount int64 `xorm:"DEFAULT 0"`
Size int64 `xorm:"DEFAULT 0"`
CreatedUnix timeutil.TimeStamp `xorm:"created"`
CustomDownloadURL string `xorm:"-"`
ID int64 `xorm:"pk autoincr"`
UUID string `xorm:"uuid UNIQUE"`
RepoID int64 `xorm:"INDEX"` // this should not be zero
IssueID int64 `xorm:"INDEX"` // maybe zero when creating
ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating
UploaderID int64 `xorm:"INDEX DEFAULT 0"` // Notice: will be zero before this column added
CommentID int64 `xorm:"INDEX"`
Name string
DownloadCount int64 `xorm:"DEFAULT 0"`
Size int64 `xorm:"DEFAULT 0"`
CreatedUnix timeutil.TimeStamp `xorm:"created"`
}
// Prepare and load the testing database

View File

@ -151,24 +151,31 @@ func cleanAttachments(ctx context.Context, attachmentIDs []int64) []int64 {
// ScanToBeDeletedAttachments scans for attachments that are marked as to be deleted and send to
// clean queue
func ScanToBeDeletedAttachments(ctx context.Context) error {
attachments := make([]*repo_model.Attachment, 0, 10)
attachmentIDs := make([]int64, 0, 100)
lastID := int64(0)
for {
if err := db.GetEngine(ctx).
Select("id").
// use the status and id index to speed up the query
Where("status = ? AND id > ?", db.FileStatusToBeDeleted, lastID).
Asc("id").
Limit(100).
Find(&attachments); err != nil {
Find(&attachmentIDs); err != nil {
return fmt.Errorf("scan to-be-deleted attachments: %w", err)
}
if len(attachments) == 0 {
if len(attachmentIDs) == 0 {
log.Trace("No more attachments to be deleted")
break
}
AddAttachmentsToCleanQueue(ctx, attachments)
lastID = attachments[len(attachments)-1].ID
for _, id := range attachmentIDs {
if err := cleanQueue.Push(id); err != nil {
log.Error("Failed to push attachment ID %d to clean queue: %v", id, err)
}
}
lastID = attachmentIDs[len(attachmentIDs)-1]
attachmentIDs = attachmentIDs[0:0]
}
return nil

View File

@ -318,7 +318,9 @@ func deleteIssue(ctx context.Context, issue *issues_model.Issue, deleteAttachmen
if err := deleteComment(ctx, comment, deleteAttachments); err != nil {
return nil, fmt.Errorf("deleteComment [comment_id: %d]: %w", comment.ID, err)
}
toBeCleanedAttachments = append(toBeCleanedAttachments, comment.Attachments...)
if deleteAttachments {
toBeCleanedAttachments = append(toBeCleanedAttachments, comment.Attachments...)
}
}
if deleteAttachments {