mirror of
https://github.com/go-gitea/gitea.git
synced 2025-08-21 14:44:17 +00:00
Some improvements
This commit is contained in:
parent
3b2e424820
commit
a15917611c
@ -99,7 +99,7 @@
|
|||||||
comment_id: 0
|
comment_id: 0
|
||||||
name: attach1
|
name: attach1
|
||||||
download_count: 0
|
download_count: 0
|
||||||
size: 0
|
size: 29
|
||||||
created_unix: 946684800
|
created_unix: 946684800
|
||||||
|
|
||||||
-
|
-
|
||||||
@ -153,16 +153,3 @@
|
|||||||
download_count: 0
|
download_count: 0
|
||||||
size: 0
|
size: 0
|
||||||
created_unix: 946684800
|
created_unix: 946684800
|
||||||
|
|
||||||
-
|
|
||||||
id: 13
|
|
||||||
uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a23
|
|
||||||
repo_id: 1
|
|
||||||
issue_id: 3
|
|
||||||
release_id: 0
|
|
||||||
uploader_id: 0
|
|
||||||
comment_id: 7
|
|
||||||
name: code_comment_uploaded_attachment.png
|
|
||||||
download_count: 0
|
|
||||||
size: 0
|
|
||||||
created_unix: 946684812
|
|
||||||
|
@ -6,13 +6,16 @@ package attachment
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/storage"
|
||||||
"code.gitea.io/gitea/services/storagecleanup"
|
"code.gitea.io/gitea/services/storagecleanup"
|
||||||
|
|
||||||
_ "code.gitea.io/gitea/models/actions"
|
_ "code.gitea.io/gitea/models/actions"
|
||||||
@ -55,12 +58,26 @@ func TestUploadAttachment(t *testing.T) {
|
|||||||
func TestDeleteAttachments(t *testing.T) {
|
func TestDeleteAttachments(t *testing.T) {
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
attachment8 := unittest.AssertExistsAndLoadBean(t, &repo_model.Attachment{ID: 8})
|
attachment8 := unittest.AssertExistsAndLoadBean(t, &repo_model.Attachment{ID: 8})
|
||||||
|
const attachment8Content = "test content for attachment 8" // 29 bytes
|
||||||
err := DeleteAttachment(db.DefaultContext, attachment8)
|
_, err := storage.Attachments.Save(attachment8.RelativePath(), strings.NewReader(attachment8Content), int64(len(attachment8Content)))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
attachment, err := repo_model.GetAttachmentByUUID(db.DefaultContext, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a18")
|
fileInfo, err := storage.Attachments.Stat(attachment8.RelativePath())
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, attachment8.Size, fileInfo.Size())
|
||||||
|
|
||||||
|
err = DeleteAttachment(db.DefaultContext, attachment8)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
attachment, err := repo_model.GetAttachmentByUUID(db.DefaultContext, attachment8.UUID)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.True(t, repo_model.IsErrAttachmentNotExist(err))
|
assert.True(t, repo_model.IsErrAttachmentNotExist(err))
|
||||||
assert.Nil(t, attachment)
|
assert.Nil(t, attachment)
|
||||||
|
|
||||||
|
// allow the queue to process the deletion
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
|
_, err = storage.Attachments.Stat(attachment8.RelativePath())
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.True(t, os.IsNotExist(err))
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,6 @@ func deleteComment(ctx context.Context, comment *issues_model.Comment, removeAtt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// deletedReviewComment should be a review comment with no content and no attachments
|
|
||||||
if err := issues_model.DeleteComment(ctx, comment); err != nil {
|
if err := issues_model.DeleteComment(ctx, comment); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,7 @@ func cleanupDeletions(ctx context.Context, deletionIDs []int64) []int64 {
|
|||||||
deletion, exist, err := db.GetByID[system.StoragePathDeletion](ctx, deletionID)
|
deletion, exist, err := db.GetByID[system.StoragePathDeletion](ctx, deletionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to get deletion by ID %d: %v", deletionID, err)
|
log.Error("Failed to get deletion by ID %d: %v", deletionID, err)
|
||||||
|
failed = append(failed, deletionID)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !exist {
|
if !exist {
|
||||||
@ -57,6 +58,7 @@ func cleanupDeletions(ctx context.Context, deletionIDs []int64) []int64 {
|
|||||||
theStorage, err := storage.GetStorageByName(deletion.StorageName)
|
theStorage, err := storage.GetStorageByName(deletion.StorageName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to get storage by name %s: %v", deletion.StorageName, err)
|
log.Error("Failed to get storage by name %s: %v", deletion.StorageName, err)
|
||||||
|
failed = append(failed, deletionID)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := theStorage.Delete(deletion.RelativePath); err != nil {
|
if err := theStorage.Delete(deletion.RelativePath); err != nil {
|
||||||
@ -90,7 +92,6 @@ func ScanToBeDeletedFilesOrDir(ctx context.Context) error {
|
|||||||
for {
|
for {
|
||||||
if err := db.GetEngine(ctx).
|
if err := db.GetEngine(ctx).
|
||||||
Select("id").
|
Select("id").
|
||||||
// use the status and id index to speed up the query
|
|
||||||
Where("id > ?", lastID).
|
Where("id > ?", lastID).
|
||||||
Asc("id").
|
Asc("id").
|
||||||
Limit(100).
|
Limit(100).
|
||||||
|
@ -100,12 +100,12 @@ func deleteUser(ctx context.Context, u *user_model.User, purge bool) (toBeCleane
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := auth_model.DeleteOAuth2RelictsByUserID(ctx, u.ID); err != nil {
|
if err := auth_model.DeleteOAuth2RelictsByUserID(ctx, u.ID); err != nil {
|
||||||
return nil, fmt.Errorf("deleteOAuth2RelictsByUserID: %w", err)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if purge || (setting.Service.UserDeleteWithCommentsMaxTime != 0 &&
|
if purge || (setting.Service.UserDeleteWithCommentsMaxTime != 0 &&
|
||||||
u.CreatedUnix.AsTime().Add(setting.Service.UserDeleteWithCommentsMaxTime).After(time.Now())) {
|
u.CreatedUnix.AsTime().Add(setting.Service.UserDeleteWithCommentsMaxTime).After(time.Now())) {
|
||||||
// Delete Comments with attachments
|
// Delete Comments
|
||||||
const batchSize = 50
|
const batchSize = 50
|
||||||
for {
|
for {
|
||||||
comments := make([]*issues_model.Comment, 0, batchSize)
|
comments := make([]*issues_model.Comment, 0, batchSize)
|
||||||
|
Loading…
Reference in New Issue
Block a user