From ae2c93318152fd83aa0224c457835bf9393e3f1f Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Wed, 9 Feb 2011 20:27:24 +0800 Subject: [PATCH] Destroy all messages in one sqlite transaction --- .../k9/controller/MessagingController.java | 14 +++++++++---- src/com/fsck/k9/mail/store/LocalStore.java | 21 +++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java index d053443fe..c8be8feab 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -1005,13 +1005,19 @@ public class MessagingController implements Runnable { * Remove any messages that are in the local store but no longer on the remote store or are too old */ if (account.syncRemoteDeletions()) { + ArrayList destroyMessages = new ArrayList(); for (Message localMessage : localMessages) { if (remoteUidMap.get(localMessage.getUid()) == null) { - localMessage.destroy(); + destroyMessages.add(localMessage); + } + } - for (MessagingListener l : getListeners(listener)) { - l.synchronizeMailboxRemovedMessage(account, folder, localMessage); - } + + localFolder.destroyMessages(destroyMessages.toArray(EMPTY_MESSAGE_ARRAY)); + + for (Message destroyMessage : destroyMessages) { + for (MessagingListener l : getListeners(listener)) { + l.synchronizeMailboxRemovedMessage(account, folder, destroyMessage); } } } diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index f706ed8de..672554921 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -2020,6 +2020,27 @@ public class LocalStore extends Store implements Serializable { appendMessages(messages, false); } + public void destroyMessages(final Message[] messages) throws MessagingException { + try { + database.execute(true, new DbCallback() { + @Override + public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { + for (Message message : messages) { + try { + message.destroy(); + } catch (MessagingException e) { + throw new WrappedException(e); + } + } + return null; + } + }); + } catch (MessagingException e) { + throw new WrappedException(e); + } + } + + /** * The method differs slightly from the contract; If an incoming message already has a uid * assigned and it matches the uid of an existing message then this message will replace the