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

Use one database transaction when doing bulk flag changes

Previously we used one transaction per message. For 500 messages the
database updates alone took over 30s on my Nexus 7.
This commit is contained in:
cketti 2012-11-27 16:46:59 +01:00
parent 3b022cd72f
commit 2db8034c31

View File

@ -2795,11 +2795,30 @@ public class LocalStore extends Store implements Serializable {
}
@Override
public void setFlags(Message[] messages, Flag[] flags, boolean value)
public void setFlags(final Message[] messages, final Flag[] flags, final boolean value)
throws MessagingException {
open(OpenMode.READ_WRITE);
for (Message message : messages) {
message.setFlags(flags, value);
// Use one transaction to set all flags
try {
database.execute(true, new DbCallback<Void>() {
@Override
public Void doDbWork(final SQLiteDatabase db) throws WrappedException,
UnavailableStorageException {
for (Message message : messages) {
try {
message.setFlags(flags, value);
} catch (MessagingException e) {
Log.e(K9.LOG_TAG, "Something went wrong while setting flag", e);
}
}
return null;
}
});
} catch (WrappedException e) {
throw(MessagingException) e.getCause();
}
}