File tree 1 file changed +17
-8
lines changed
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 {
135
135
136
136
// DeleteAttachments deletes the given attachments and optionally the associated files.
137
137
func 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 {
140
154
if err := os .Remove (a .LocalPath ()); err != nil {
141
155
return i , err
142
156
}
143
157
}
144
-
145
- if _ , err := x .Delete (a ); err != nil {
146
- return i , err
147
- }
148
158
}
149
-
150
- return len (attachments ), nil
159
+ return int (cnt ), nil
151
160
}
152
161
153
162
// DeleteAttachmentsByIssue deletes all attachments associated with the given issue.
You can’t perform that action at this time.
0 commit comments