mirror of
https://github.com/go-gitea/gitea.git
synced 2025-08-20 10:05:27 +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
|
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.
|
// DeleteAttachmentsByRelease deletes all attachments associated with the given release.
|
||||||
func DeleteAttachmentsByRelease(ctx context.Context, releaseID int64) error {
|
func DeleteAttachmentsByRelease(ctx context.Context, releaseID int64) error {
|
||||||
_, err := db.GetEngine(ctx).Where("release_id = ?", releaseID).Delete(&Attachment{})
|
_, 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.
|
// DeleteAttachments deletes the given attachments and optionally the associated files.
|
||||||
func DeleteAttachments(ctx context.Context, attachments []*repo_model.Attachment) (int, error) {
|
func DeleteAttachments(ctx context.Context, attachments []*repo_model.Attachment) (int, error) {
|
||||||
if len(attachments) == 0 {
|
cnt, err := repo_model.DeleteAttachments(ctx, attachments)
|
||||||
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])
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
@ -152,8 +152,7 @@ func deleteComment(ctx context.Context, comment *issues_model.Comment, removeAtt
|
|||||||
|
|
||||||
if removeAttachments {
|
if removeAttachments {
|
||||||
// delete comment attachments
|
// delete comment attachments
|
||||||
_, err := db.GetEngine(ctx).Where("comment_id = ?", comment.ID).NoAutoCondition().Delete(&repo_model.Attachment{})
|
if _, err := repo_model.DeleteAttachments(ctx, comment.Attachments); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,13 +131,7 @@ func deleteUser(ctx context.Context, u *user_model.User, purge bool) (cleanup ut
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ids := make([]int64, 0, len(comment.Attachments))
|
if _, err := repo_model.DeleteAttachments(ctx, comment.Attachments); err != nil {
|
||||||
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 {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user