1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-24 08:38:51 -05:00

Destroy all messages in one sqlite transaction

This commit is contained in:
Matt Johnston 2011-02-09 20:27:24 +08:00 committed by Jesse Vincent
parent 0d0415e705
commit ae2c933181
2 changed files with 31 additions and 4 deletions

View File

@ -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<Message> destroyMessages = new ArrayList<Message>();
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);
}
}
}

View File

@ -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<Void>() {
@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