1
0
mirror of https://github.com/moparisthebest/k-9 synced 2025-02-25 15:11:52 -05:00

Ask SQLite for a simpler calculation when counting unread messages. The docs imply this is a decent perf win. I'm seeing at least a bit of one

This commit is contained in:
Jesse Vincent 2013-07-30 16:12:38 -04:00
parent 375d62fb7d
commit e9a0cbb269

View File

@ -1512,7 +1512,7 @@ public class LocalStore extends Store implements Serializable {
} }
Cursor cursor = null; Cursor cursor = null;
try { try {
cursor = db.rawQuery("SELECT COUNT(*) FROM messages WHERE (empty IS NULL OR empty != 1) AND deleted = 0 and folder_id = ?", cursor = db.rawQuery("SELECT COUNT(id) FROM messages WHERE (empty IS NULL OR empty != 1) AND deleted = 0 and folder_id = ?",
new String[] { new String[] {
Long.toString(mFolderId) Long.toString(mFolderId)
}); });
@ -1539,8 +1539,8 @@ public class LocalStore extends Store implements Serializable {
@Override @Override
public Integer doDbWork(final SQLiteDatabase db) throws WrappedException { public Integer doDbWork(final SQLiteDatabase db) throws WrappedException {
int unreadMessageCount = 0; int unreadMessageCount = 0;
Cursor cursor = db.query("messages", new String[] { "SUM(read=0)" }, Cursor cursor = db.query("messages", new String[] { "COUNT(id)" },
"folder_id = ? AND (empty IS NULL OR empty != 1) AND deleted = 0", "folder_id = ? AND (empty IS NULL OR empty != 1) AND deleted = 0 AND read=0",
new String[] { Long.toString(mFolderId) }, null, null, null); new String[] { Long.toString(mFolderId) }, null, null, null);
try { try {
@ -1570,8 +1570,8 @@ public class LocalStore extends Store implements Serializable {
@Override @Override
public Integer doDbWork(final SQLiteDatabase db) throws WrappedException { public Integer doDbWork(final SQLiteDatabase db) throws WrappedException {
int flaggedMessageCount = 0; int flaggedMessageCount = 0;
Cursor cursor = db.query("messages", new String[] { "SUM(flagged)" }, Cursor cursor = db.query("messages", new String[] { "COUNT(id)" },
"folder_id = ? AND (empty IS NULL OR empty != 1) AND deleted = 0", "folder_id = ? AND (empty IS NULL OR empty != 1) AND deleted = 0 AND flagged IS true",
new String[] { Long.toString(mFolderId) }, null, null, null); new String[] { Long.toString(mFolderId) }, null, null, null);
try { try {