File tree Expand file tree Collapse file tree 1 file changed +17
-8
lines changed Expand file tree Collapse file tree 1 file changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -135,19 +135,28 @@ func DeleteAttachment(a *Attachment, remove bool) error {
135135
136136// DeleteAttachments deletes the given attachments and optionally the associated files.
137137func DeleteAttachments (attachments []* Attachment , remove bool ) (int , error ) {
138- for i , a := range attachments {
139- if remove {
138+ if len (attachments ) == 0 {
139+ return 0 , nil
140+ }
141+
142+ var ids = make ([]int64 , 0 , len (attachments ))
143+ for _ , a := range attachments {
144+ ids = append (ids , a .ID )
145+ }
146+
147+ cnt , err := x .In ("id" , ids ).NoAutoCondition ().Delete (attachments [0 ])
148+ if err != nil {
149+ return 0 , err
150+ }
151+
152+ if remove {
153+ for i , a := range attachments {
140154 if err := os .Remove (a .LocalPath ()); err != nil {
141155 return i , err
142156 }
143157 }
144-
145- if _ , err := x .Delete (a ); err != nil {
146- return i , err
147- }
148158 }
149-
150- return len (attachments ), nil
159+ return int (cnt ), nil
151160}
152161
153162// DeleteAttachmentsByIssue deletes all attachments associated with the given issue.
You can’t perform that action at this time.
0 commit comments