mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-25 00:58:50 -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:
parent
e0f33b8701
commit
b5b91302f2
@ -13,8 +13,8 @@ public class FolderInfoHolder implements Comparable<FolderInfoHolder> {
|
||||
public String name;
|
||||
public String displayName;
|
||||
public long lastChecked;
|
||||
public int unreadMessageCount;
|
||||
public int flaggedMessageCount;
|
||||
public int unreadMessageCount = -1;
|
||||
public int flaggedMessageCount = -1;
|
||||
public boolean loading;
|
||||
public String status;
|
||||
public boolean lastCheckFailed;
|
||||
@ -67,24 +67,8 @@ public class FolderInfoHolder implements Comparable<FolderInfoHolder> {
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
this.unreadMessageCount = unreadCount;
|
||||
|
||||
try {
|
||||
this.flaggedMessageCount = folder.getFlaggedMessageCount();
|
||||
} catch (Exception e) {
|
||||
Log.e(K9.LOG_TAG, "Unable to get flaggedMessageCount", e);
|
||||
}
|
||||
|
||||
folder.close();
|
||||
|
||||
}
|
||||
|
@ -758,18 +758,11 @@ public class FolderList extends K9ListActivity {
|
||||
if (folderIndex >= 0) {
|
||||
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) {
|
||||
holder = new FolderInfoHolder(context, folder, mAccount, unreadMessageCount);
|
||||
holder = new FolderInfoHolder(context, folder, mAccount, -1);
|
||||
} else {
|
||||
holder.populate(context, folder, mAccount, unreadMessageCount);
|
||||
holder.populate(context, folder, mAccount, -1);
|
||||
|
||||
}
|
||||
if (folder.isInTopGroup()) {
|
||||
@ -820,12 +813,11 @@ public class FolderList extends K9ListActivity {
|
||||
return;
|
||||
}
|
||||
localFolder = account.getLocalStore().getFolder(folderName);
|
||||
int unreadMessageCount = localFolder.getUnreadMessageCount();
|
||||
FolderInfoHolder folderHolder = getFolder(folderName);
|
||||
if (folderHolder != null) {
|
||||
int oldUnreadMessageCount = folderHolder.unreadMessageCount;
|
||||
mUnreadMessageCount += unreadMessageCount - oldUnreadMessageCount;
|
||||
folderHolder.populate(context, localFolder, mAccount, unreadMessageCount);
|
||||
folderHolder.populate(context, localFolder, mAccount, -1);
|
||||
folderHolder.flaggedMessageCount = -1;
|
||||
|
||||
mHandler.dataChanged();
|
||||
}
|
||||
}
|
||||
@ -1031,7 +1023,16 @@ public class FolderList extends K9ListActivity {
|
||||
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.newMessageCountWrapper.setOnClickListener(
|
||||
createUnreadSearch(mAccount, folder));
|
||||
@ -1042,6 +1043,17 @@ public class FolderList extends K9ListActivity {
|
||||
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) {
|
||||
holder.flaggedMessageCount.setText(Integer.toString(folder.flaggedMessageCount));
|
||||
holder.flaggedMessageCountWrapper.setOnClickListener(
|
||||
|
Loading…
Reference in New Issue
Block a user