From 54a4c84afaba04683a4652b8e083652c77e1d3a4 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sun, 29 Aug 2010 16:56:45 +0000 Subject: [PATCH] Split out deleteAttachment to avoid an extra SQL call if we can. --- src/com/fsck/k9/mail/store/LocalStore.java | 76 ++++++++++++---------- 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index f6be49570..a87c9581f 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -2261,6 +2261,47 @@ public class LocalStore extends Store implements Serializable return PERMANENT_FLAGS; } + + private void deleteAttachments(long messageId) throws MessagingException + { + open(OpenMode.READ_WRITE); + Cursor attachmentsCursor = null; + try + { + attachmentsCursor = mDb.query( + "attachments", + new String[] { "id" }, + "message_id = ?", + new String[] { Long.toString(messageId) }, + null, + null, + null); + while (attachmentsCursor.moveToNext()) + { + long attachmentId = attachmentsCursor.getLong(0); + try + { + File file = new File(mAttachmentsDir, Long.toString(attachmentId)); + if (file.exists()) + { + file.delete(); + } + } + catch (Exception e) + { + + } + } + } + finally + { + if (attachmentsCursor != null) + { + attachmentsCursor.close(); + } + } + } + private void deleteAttachments(String uid) throws MessagingException { open(OpenMode.READ_WRITE); @@ -2278,41 +2319,8 @@ public class LocalStore extends Store implements Serializable while (messagesCursor.moveToNext()) { long messageId = messagesCursor.getLong(0); - Cursor attachmentsCursor = null; - try - { - attachmentsCursor = mDb.query( - "attachments", - new String[] { "id" }, - "message_id = ?", - new String[] { Long.toString(messageId) }, - null, - null, - null); - while (attachmentsCursor.moveToNext()) - { - long attachmentId = attachmentsCursor.getLong(0); - try - { - File file = new File(mAttachmentsDir, Long.toString(attachmentId)); - if (file.exists()) - { - file.delete(); - } - } - catch (Exception e) - { + deleteAttachments(messageId); - } - } - } - finally - { - if (attachmentsCursor != null) - { - attachmentsCursor.close(); - } - } } } finally