1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-24 02:12:15 -05:00

lazify loading of message headers in LocalFolder, since they're not needed in most of our use cases.

This commit is contained in:
Jesse Vincent 2009-12-15 02:51:18 +00:00
parent 7974d7b59c
commit 7b811e45a1

View File

@ -1241,9 +1241,6 @@ public class LocalStore extends Store implements Serializable
return null; return null;
} }
populateMessageFromGetMessageCursor(message, cursor); populateMessageFromGetMessageCursor(message, cursor);
ArrayList<LocalMessage> messages = new ArrayList<LocalMessage>();
messages.add(message);
populateHeaders(messages);
} }
finally finally
{ {
@ -1291,19 +1288,12 @@ public class LocalStore extends Store implements Serializable
populateMessageFromGetMessageCursor(message, cursor); populateMessageFromGetMessageCursor(message, cursor);
messages.add(message); messages.add(message);
messagesForHeaders.add(message);
if (messagesForHeaders.size() >= 50)
{
populateHeaders(messagesForHeaders);
messagesForHeaders.clear();
}
if (listener != null) if (listener != null)
{ {
listener.messageFinished(message, i, -1); listener.messageFinished(message, i, -1);
} }
i++; i++;
} }
populateHeaders(messagesForHeaders);
if (listener != null) if (listener != null)
{ {
listener.messagesFinished(i); listener.messagesFinished(i);
@ -2052,7 +2042,7 @@ public class LocalStore extends Store implements Serializable
private int mAttachmentCount; private int mAttachmentCount;
private String mSubject; private String mSubject;
private boolean mHeadersLoaded = false;
private boolean mMessageDirty = false; private boolean mMessageDirty = false;
public LocalMessage() public LocalMessage()
@ -2296,6 +2286,49 @@ public class LocalStore extends Store implements Serializable
Utility.combine(getFlags(), ',').toUpperCase(), mId Utility.combine(getFlags(), ',').toUpperCase(), mId
}); });
} }
private void loadHeaders() {
ArrayList<LocalMessage> messages = new ArrayList<LocalMessage>();
messages.add(this);
mHeadersLoaded = true; // set true before calling populate headers to stop recursion
((LocalFolder) mFolder).populateHeaders(messages);
}
public void addHeader(String name, String value)
{
if (!mHeadersLoaded)
{
loadHeaders();
}
super.addHeader(name, value);
}
public void setHeader(String name, String value)
{
if (!mHeadersLoaded)
loadHeaders();
super.setHeader(name, value);
}
public String[] getHeader(String name)
{
if (!mHeadersLoaded)
loadHeaders();
return super.getHeader(name);
}
public void removeHeader(String name)
{
if (!mHeadersLoaded)
loadHeaders();
super.removeHeader(name);
}
} }
public class LocalAttachmentBodyPart extends MimeBodyPart public class LocalAttachmentBodyPart extends MimeBodyPart