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
1 changed files with 5 additions and 5 deletions

View File

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