From 7dffacf9577c32065b3b4765a933b4e805d4f8b7 Mon Sep 17 00:00:00 2001 From: Anton Chekulaev Date: Wed, 30 Sep 2020 17:33:53 +1000 Subject: [PATCH] Avatar check optimization. --- src/org/thoughtcrime/securesms/database/GroupDatabase.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/org/thoughtcrime/securesms/database/GroupDatabase.java b/src/org/thoughtcrime/securesms/database/GroupDatabase.java index 893cddf9f0..95db6f1b99 100644 --- a/src/org/thoughtcrime/securesms/database/GroupDatabase.java +++ b/src/org/thoughtcrime/securesms/database/GroupDatabase.java @@ -276,10 +276,10 @@ public class GroupDatabase extends Database implements LokiGroupDatabaseProtocol public boolean hasAvatar(String groupId) { try (Cursor cursor = databaseHelper.getReadableDatabase().rawQuery( - "SELECT COUNT("+ID+") FROM "+TABLE_NAME+" WHERE "+GROUP_ID+" == ? AND "+AVATAR+" NOT NULL", + "SELECT EXISTS(SELECT 1 FROM "+TABLE_NAME+" WHERE "+GROUP_ID+" == ? AND "+AVATAR+" NOT NULL LIMIT 1)", new String[]{groupId})) { cursor.moveToFirst(); - return cursor.getInt(0) > 0; + return cursor.getInt(0) == 1; } }