mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 19:52:17 -05:00
Execute LocalMessage.appendMessage() & LocalMessage.setFlag() in the same transaction for small message storing in order to speed up DB update.
This is a per message basis optimization. More improved speed could be attained by batching several messages in the same transaction.
This commit is contained in:
parent
bb5052f848
commit
c5f7dbf028
@ -1783,13 +1783,14 @@ public class MessagingController implements Runnable
|
||||
}
|
||||
|
||||
// Store the updated message locally
|
||||
localFolder.appendMessages(new Message[] { message });
|
||||
|
||||
Message localMessage = localFolder.getMessage(message.getUid());
|
||||
progress.incrementAndGet();
|
||||
|
||||
// Set a flag indicating this message has now be fully downloaded
|
||||
localMessage.setFlag(Flag.X_DOWNLOADED_FULL, true);
|
||||
final Message localMessage = localFolder.storeSmallMessage(message, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
progress.incrementAndGet();
|
||||
}
|
||||
});
|
||||
if (K9.DEBUG)
|
||||
Log.v(K9.LOG_TAG, "About to notify listeners that we got a new small message "
|
||||
+ account + ":" + folder + ":" + message.getUid());
|
||||
|
@ -2842,6 +2842,39 @@ public class LocalStore extends Store implements Serializable, LocalStoreMigrati
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience transaction wrapper for storing a message and set it as fully downloaded. Implemented mainly to speed up DB transaction commit.
|
||||
*
|
||||
* @param message Message to store. Never <code>null</code>.
|
||||
* @param runnable What to do before setting {@link Flag#X_DOWNLOADED_FULL}. Never <code>null</code>.
|
||||
* @return The local version of the message. Never <code>null</code>.
|
||||
* @throws MessagingException
|
||||
*/
|
||||
public Message storeSmallMessage(final Message message, final Runnable runnable) throws MessagingException
|
||||
{
|
||||
return execute(true, new DbCallback<Message>()
|
||||
{
|
||||
@Override
|
||||
public Message doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException
|
||||
{
|
||||
try
|
||||
{
|
||||
appendMessages(new Message[] { message });
|
||||
final String uid = message.getUid();
|
||||
final Message result = getMessage(uid);
|
||||
runnable.run();
|
||||
// Set a flag indicating this message has now be fully downloaded
|
||||
result.setFlag(Flag.X_DOWNLOADED_FULL, true);
|
||||
return result;
|
||||
}
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user