1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-25 09:08:49 -05:00

Load unread and flagged message counts lazily in the folder list

The new method is a little bit janky, but a little bit of jank is better than 2n
heavy SQL count queries per folder before we even show the folder list.

On my 200 folder account, display of the folder list activity drops from 10+s to
< 1s
This commit is contained in:
Jesse Vincent 2013-08-26 23:07:24 -04:00
parent e0f33b8701
commit b5b91302f2
2 changed files with 28 additions and 32 deletions

View File

@ -13,8 +13,8 @@ public class FolderInfoHolder implements Comparable<FolderInfoHolder> {
public String name; public String name;
public String displayName; public String displayName;
public long lastChecked; public long lastChecked;
public int unreadMessageCount; public int unreadMessageCount = -1;
public int flaggedMessageCount; public int flaggedMessageCount = -1;
public boolean loading; public boolean loading;
public String status; public String status;
public boolean lastCheckFailed; public boolean lastCheckFailed;
@ -67,24 +67,8 @@ public class FolderInfoHolder implements Comparable<FolderInfoHolder> {
} }
public void populate(Context context, Folder folder, Account account, int unreadCount) { public void populate(Context context, Folder folder, Account account, int unreadCount) {
try {
folder.open(Folder.OPEN_MODE_RW);
// unreadCount = folder.getUnreadMessageCount();
} catch (MessagingException me) {
Log.e(K9.LOG_TAG, "Folder.getUnreadMessageCount() failed", me);
}
populate(context, folder, account); populate(context, folder, account);
this.unreadMessageCount = unreadCount; this.unreadMessageCount = unreadCount;
try {
this.flaggedMessageCount = folder.getFlaggedMessageCount();
} catch (Exception e) {
Log.e(K9.LOG_TAG, "Unable to get flaggedMessageCount", e);
}
folder.close(); folder.close();
} }

View File

@ -758,18 +758,11 @@ public class FolderList extends K9ListActivity {
if (folderIndex >= 0) { if (folderIndex >= 0) {
holder = (FolderInfoHolder) getItem(folderIndex); holder = (FolderInfoHolder) getItem(folderIndex);
} }
int unreadMessageCount = 0;
try {
unreadMessageCount = folder.getUnreadMessageCount();
} catch (Exception e) {
Log.e(K9.LOG_TAG, "Unable to get unreadMessageCount for " + mAccount.getDescription() + ":"
+ folder.getName());
}
if (holder == null) { if (holder == null) {
holder = new FolderInfoHolder(context, folder, mAccount, unreadMessageCount); holder = new FolderInfoHolder(context, folder, mAccount, -1);
} else { } else {
holder.populate(context, folder, mAccount, unreadMessageCount); holder.populate(context, folder, mAccount, -1);
} }
if (folder.isInTopGroup()) { if (folder.isInTopGroup()) {
@ -820,12 +813,11 @@ public class FolderList extends K9ListActivity {
return; return;
} }
localFolder = account.getLocalStore().getFolder(folderName); localFolder = account.getLocalStore().getFolder(folderName);
int unreadMessageCount = localFolder.getUnreadMessageCount();
FolderInfoHolder folderHolder = getFolder(folderName); FolderInfoHolder folderHolder = getFolder(folderName);
if (folderHolder != null) { if (folderHolder != null) {
int oldUnreadMessageCount = folderHolder.unreadMessageCount; folderHolder.populate(context, localFolder, mAccount, -1);
mUnreadMessageCount += unreadMessageCount - oldUnreadMessageCount; folderHolder.flaggedMessageCount = -1;
folderHolder.populate(context, localFolder, mAccount, unreadMessageCount);
mHandler.dataChanged(); mHandler.dataChanged();
} }
} }
@ -1031,7 +1023,16 @@ public class FolderList extends K9ListActivity {
holder.folderStatus.setVisibility(View.GONE); holder.folderStatus.setVisibility(View.GONE);
} }
if (folder.unreadMessageCount != 0) { if(folder.unreadMessageCount == -1) {
folder.unreadMessageCount = 0;
try {
folder.unreadMessageCount = folder.folder.getUnreadMessageCount();
} catch (Exception e) {
Log.e(K9.LOG_TAG, "Unable to get unreadMessageCount for " + mAccount.getDescription() + ":"
+ folder.name);
}
}
if (folder.unreadMessageCount > 0) {
holder.newMessageCount.setText(Integer.toString(folder.unreadMessageCount)); holder.newMessageCount.setText(Integer.toString(folder.unreadMessageCount));
holder.newMessageCountWrapper.setOnClickListener( holder.newMessageCountWrapper.setOnClickListener(
createUnreadSearch(mAccount, folder)); createUnreadSearch(mAccount, folder));
@ -1042,6 +1043,17 @@ public class FolderList extends K9ListActivity {
holder.newMessageCountWrapper.setVisibility(View.GONE); holder.newMessageCountWrapper.setVisibility(View.GONE);
} }
if (folder.flaggedMessageCount == -1) {
folder.flaggedMessageCount = 0;
try {
folder.flaggedMessageCount = folder.folder.getFlaggedMessageCount();
} catch (Exception e) {
Log.e(K9.LOG_TAG, "Unable to get flaggedMessageCount for " + mAccount.getDescription() + ":"
+ folder.name);
}
}
if (K9.messageListStars() && folder.flaggedMessageCount > 0) { if (K9.messageListStars() && folder.flaggedMessageCount > 0) {
holder.flaggedMessageCount.setText(Integer.toString(folder.flaggedMessageCount)); holder.flaggedMessageCount.setText(Integer.toString(folder.flaggedMessageCount));
holder.flaggedMessageCountWrapper.setOnClickListener( holder.flaggedMessageCountWrapper.setOnClickListener(