mirror of
https://github.com/go-gitea/gitea.git
synced 2025-08-19 18:21:59 +00:00
improvements
This commit is contained in:
parent
3abb7571a8
commit
8f97a2d0b1
@ -185,6 +185,19 @@ func UpdateAttachment(ctx context.Context, atta *Attachment) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func DeleteAttachments(ctx context.Context, attachments []*Attachment) (int64, error) {
|
||||
if len(attachments) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
ids := make([]int64, 0, len(attachments))
|
||||
for _, a := range attachments {
|
||||
ids = append(ids, a.ID)
|
||||
}
|
||||
|
||||
return db.GetEngine(ctx).In("id", ids).NoAutoCondition().Delete(attachments[0])
|
||||
}
|
||||
|
||||
// DeleteAttachmentsByRelease deletes all attachments associated with the given release.
|
||||
func DeleteAttachmentsByRelease(ctx context.Context, releaseID int64) error {
|
||||
_, err := db.GetEngine(ctx).Where("release_id = ?", releaseID).Delete(&Attachment{})
|
||||
|
@ -71,16 +71,7 @@ func DeleteAttachment(ctx context.Context, a *repo_model.Attachment) error {
|
||||
|
||||
// DeleteAttachments deletes the given attachments and optionally the associated files.
|
||||
func DeleteAttachments(ctx context.Context, attachments []*repo_model.Attachment) (int, error) {
|
||||
if len(attachments) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
ids := make([]int64, 0, len(attachments))
|
||||
for _, a := range attachments {
|
||||
ids = append(ids, a.ID)
|
||||
}
|
||||
|
||||
cnt, err := db.GetEngine(ctx).In("id", ids).NoAutoCondition().Delete(attachments[0])
|
||||
cnt, err := repo_model.DeleteAttachments(ctx, attachments)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
@ -152,8 +152,7 @@ func deleteComment(ctx context.Context, comment *issues_model.Comment, removeAtt
|
||||
|
||||
if removeAttachments {
|
||||
// delete comment attachments
|
||||
_, err := db.GetEngine(ctx).Where("comment_id = ?", comment.ID).NoAutoCondition().Delete(&repo_model.Attachment{})
|
||||
if err != nil {
|
||||
if _, err := repo_model.DeleteAttachments(ctx, comment.Attachments); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -131,13 +131,7 @@ func deleteUser(ctx context.Context, u *user_model.User, purge bool) (cleanup ut
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ids := make([]int64, 0, len(comment.Attachments))
|
||||
for _, a := range comment.Attachments {
|
||||
ids = append(ids, a.ID)
|
||||
}
|
||||
|
||||
_, err := db.GetEngine(ctx).In("id", ids).NoAutoCondition().Delete(&repo_model.Attachment{})
|
||||
if err != nil {
|
||||
if _, err := repo_model.DeleteAttachments(ctx, comment.Attachments); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user