mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 19:52:17 -05:00
Replace the expensive part of Account.getStats() that loaded all folders
and iterated through them with a SQL query.
This commit is contained in:
parent
5a5541b400
commit
30fed01784
@ -642,54 +642,11 @@ public class Account implements BaseAccount
|
||||
{
|
||||
stats.size = localStore.getSize();
|
||||
}
|
||||
Account.FolderMode aMode = getFolderDisplayMode();
|
||||
Preferences prefs = Preferences.getPreferences(context);
|
||||
long folderLoadStart = System.currentTimeMillis();
|
||||
List<? extends Folder> folders = localStore.getPersonalNamespaces(false);
|
||||
long folderLoadEnd = System.currentTimeMillis();
|
||||
for (Folder folder : folders)
|
||||
{
|
||||
LocalFolder localFolder = (LocalFolder)folder;
|
||||
//folder.refresh(prefs);
|
||||
Folder.FolderClass fMode = localFolder.getDisplayClass();
|
||||
|
||||
// Always get stats about the INBOX (see issue 1817)
|
||||
if (!folder.getName().equals(K9.INBOX) && isSpecialFolder(folder.getName()) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (aMode == Account.FolderMode.NONE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (aMode == Account.FolderMode.FIRST_CLASS &&
|
||||
fMode != Folder.FolderClass.FIRST_CLASS)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (aMode == Account.FolderMode.FIRST_AND_SECOND_CLASS &&
|
||||
fMode != Folder.FolderClass.FIRST_CLASS &&
|
||||
fMode != Folder.FolderClass.SECOND_CLASS)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (aMode == Account.FolderMode.NOT_SECOND_CLASS &&
|
||||
fMode == Folder.FolderClass.SECOND_CLASS)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
unreadMessageCount += folder.getUnreadMessageCount();
|
||||
flaggedMessageCount += folder.getFlaggedMessageCount();
|
||||
|
||||
}
|
||||
long folderEvalEnd = System.currentTimeMillis();
|
||||
stats.unreadMessageCount = unreadMessageCount;
|
||||
stats.flaggedMessageCount = flaggedMessageCount;
|
||||
localStore.getMessageCounts(stats);
|
||||
long endTime = System.currentTimeMillis();
|
||||
if (K9.DEBUG)
|
||||
Log.d(K9.LOG_TAG, "Account.getStats() on " + getDescription() + " took " + (endTime - startTime) + " ms;"
|
||||
+ " loading " + folders.size() + " took " + (folderLoadEnd - folderLoadStart) + " ms;"
|
||||
+ " evaluating took " + (folderEvalEnd - folderLoadEnd) + " ms");
|
||||
Log.d(K9.LOG_TAG, "Account.getStats() on " + getDescription() + " took " + (endTime - startTime) + " ms;");
|
||||
return stats;
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,8 @@ import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import com.fsck.k9.Account;
|
||||
import com.fsck.k9.Account.FolderMode;
|
||||
import com.fsck.k9.AccountStats;
|
||||
import com.fsck.k9.K9;
|
||||
import com.fsck.k9.Preferences;
|
||||
import com.fsck.k9.controller.MessageRemovalListener;
|
||||
@ -39,6 +41,7 @@ import com.fsck.k9.mail.BodyPart;
|
||||
import com.fsck.k9.mail.FetchProfile;
|
||||
import com.fsck.k9.mail.Flag;
|
||||
import com.fsck.k9.mail.Folder;
|
||||
import com.fsck.k9.mail.Folder.FolderClass;
|
||||
import com.fsck.k9.mail.Message;
|
||||
import com.fsck.k9.mail.Message.RecipientType;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
@ -569,6 +572,64 @@ public class LocalStore extends Store implements Serializable
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void getMessageCounts(final AccountStats stats) throws MessagingException
|
||||
{
|
||||
final Account.FolderMode displayMode = mAccount.getFolderDisplayMode();
|
||||
|
||||
database.execute(false, new DbCallback<Integer>()
|
||||
{
|
||||
@Override
|
||||
public Integer doDbWork(final SQLiteDatabase db)
|
||||
{
|
||||
Cursor cursor = null;
|
||||
try
|
||||
{
|
||||
String baseQuery = "SELECT SUM(unread_count), SUM(flagged_count) FROM FOLDERS WHERE name = ?";
|
||||
|
||||
|
||||
if (displayMode == Account.FolderMode.NONE)
|
||||
{
|
||||
cursor = db.rawQuery(baseQuery, new String[] { K9.INBOX});
|
||||
}
|
||||
else if (displayMode == Account.FolderMode.FIRST_CLASS )
|
||||
{
|
||||
cursor = db.rawQuery(baseQuery + " OR display_class = ?", new String[] { K9.INBOX, Folder.FolderClass.FIRST_CLASS.name()});
|
||||
|
||||
|
||||
}
|
||||
else if (displayMode == Account.FolderMode.FIRST_AND_SECOND_CLASS)
|
||||
{
|
||||
cursor = db.rawQuery(baseQuery + " OR display_class = ? OR display_class = ? ", new String[] { K9.INBOX, Folder.FolderClass.FIRST_CLASS.name(), Folder.FolderClass.SECOND_CLASS.name()});
|
||||
}
|
||||
else if (displayMode == Account.FolderMode.NOT_SECOND_CLASS)
|
||||
{
|
||||
cursor = db.rawQuery(baseQuery + " OR display_class != ?", new String[] { K9.INBOX, Folder.FolderClass.SECOND_CLASS.name()});
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.e(K9.LOG_TAG,"asked to compute account statistics for an impossible folder mode "+displayMode);
|
||||
}
|
||||
cursor.moveToFirst();
|
||||
stats.unreadMessageCount = cursor.getInt(0); // message count
|
||||
stats.flaggedMessageCount = cursor.getInt(1); // message count
|
||||
return null;
|
||||
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (cursor != null)
|
||||
{
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public int getFolderCount() throws MessagingException
|
||||
{
|
||||
return database.execute(false, new DbCallback<Integer>()
|
||||
|
Loading…
Reference in New Issue
Block a user