-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Improve attachments deletion #35103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lunny
wants to merge
44
commits into
go-gitea:main
Choose a base branch
from
lunny:lunny/fix_bug_delete_code_comment
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Improve attachments deletion #35103
Changes from 22 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
000d87e
Fix deleting code comment bug
lunny 012b4e5
improve the test
lunny 5cc3388
Remove AfterDelete function in comment
lunny 2d423dc
Fix bug
lunny 3abb757
improvements
lunny 8f97a2d
improvements
lunny 1742489
improvements
lunny 63173a6
fix test
lunny 6b66c30
revert unnecessary change
lunny cdb6147
revert unnecessary change
lunny 85e6668
Rename the function for post database transaction
lunny f868da0
Rename
lunny 97556a8
Improve attachments deletions
lunny b89b277
improvements
lunny 488e658
improvements
lunny e00c7d3
improvements
lunny 27c83de
improvements
lunny 0379d4b
Fix test
lunny 804022b
Fix test
lunny c89d939
Fix test
lunny 0295c7b
improve the comment
lunny 551f8ba
Fix test
lunny 9c251fd
Fix some problems
lunny 0c9f37d
revert unnecessary change in this pull request
lunny 70d2960
revert unnecessary change in this pull request
lunny f24dc5e
revert unnecessary change in this pull request
lunny 9faf99d
Fix bug
lunny df456dd
fix lint
lunny fa5fc02
Revert unnecessary changes
lunny 7134ad9
Fix test
lunny e50adec
Fix
lunny ccb8c9b
Merge branch 'main' into lunny/fix_bug_delete_code_comment
lunny 8f8dd8c
Fix test
lunny 3b2e424
Use a standalone table to store deletion files so that all kinds of s…
lunny a159176
Some improvements
lunny 9b164e0
Fix comment
lunny 4ff5c97
Merge branch 'main' into lunny/fix_bug_delete_code_comment
lunny 9671f2e
revert unrelated change
lunny e1fa778
Use cron only for deleting the files need to be cleanup
lunny ab813a9
Merge branch 'main' into lunny/fix_bug_delete_code_comment
lunny 50b9222
Cleanup cron task should be enabled by default
lunny 4330b6e
fix bug
lunny cbef386
improvement
lunny ed44e0d
Fix lint
lunny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright 2025 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package db | ||
|
||
// FileStatus represents the status of a file in the disk. | ||
type FileStatus int | ||
|
||
const ( | ||
FileStatusNormal FileStatus = iota // FileStatusNormal indicates the file is normal and exists on disk. | ||
lunny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
FileStatusToBeDeleted // FileStatusToBeDeleted indicates the file is marked for deletion but still exists on disk. | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package v1_25 | ||
|
||
import ( | ||
"testing" | ||
|
||
"code.gitea.io/gitea/models/migrations/base" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
base.MainTest(m) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2025 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package v1_25 | ||
|
||
import ( | ||
"code.gitea.io/gitea/models/db" | ||
"code.gitea.io/gitea/modules/timeutil" | ||
|
||
"xorm.io/xorm" | ||
) | ||
|
||
func AddFileStatusToAttachment(x *xorm.Engine) error { | ||
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"` | ||
Status db.FileStatus `xorm:"INDEX DEFAULT 0"` | ||
DeleteFailedCount int `xorm:"DEFAULT 0"` // Number of times the deletion failed, used to prevent infinite loop | ||
LastDeleteFailedTime timeutil.TimeStamp // Last time the deletion failed, used to prevent infinite loop | ||
Size int64 `xorm:"DEFAULT 0"` | ||
CreatedUnix timeutil.TimeStamp `xorm:"created"` | ||
CustomDownloadURL string `xorm:"-"` | ||
lunny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if err := x.Sync(new(Attachment)); err != nil { | ||
return err | ||
} | ||
|
||
if _, err := x.Exec("UPDATE `attachment` SET status = ? WHERE status IS NULL", db.FileStatusNormal); err != nil { | ||
lunny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2025 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package v1_25 | ||
|
||
import ( | ||
"testing" | ||
|
||
"code.gitea.io/gitea/models/migrations/base" | ||
"code.gitea.io/gitea/modules/timeutil" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
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:"-"` | ||
} | ||
|
||
// Prepare and load the testing database | ||
x, deferable := base.PrepareTestEnv(t, 0, new(Attachment)) | ||
defer deferable() | ||
|
||
assert.NoError(t, AddFileStatusToAttachment(x)) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.