Skip to content

Commit 2942b7a

Browse files
committed
improve the sequence of deletion
1 parent b32dd8c commit 2942b7a

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

models/attachment.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,23 @@ func DeleteAttachments(attachments []*Attachment, remove bool) (int, error) {
140140
}
141141

142142
var ids = make([]int64, 0, len(attachments))
143-
for i, a := range attachments {
144-
if remove {
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 {
145154
if err := os.Remove(a.LocalPath()); err != nil {
146155
return i, err
147156
}
148157
}
149-
ids = append(ids, a.ID)
150158
}
151-
152-
cnt, err := x.In("id", ids).NoAutoCondition().Delete(attachments[0])
153-
return int(cnt), err
159+
return int(cnt), nil
154160
}
155161

156162
// DeleteAttachmentsByIssue deletes all attachments associated with the given issue.

0 commit comments

Comments
 (0)