From f551a700fe20ef3e3ae5f7526c50f17194150787 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Thu, 25 Aug 2022 14:26:17 -0400 Subject: [PATCH] Fix crash when searching groups for a large number of members. --- .../org/thoughtcrime/securesms/database/GroupDatabase.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/GroupDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/GroupDatabase.java index 48c3599c7..766cc6dc0 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/GroupDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/GroupDatabase.java @@ -299,6 +299,11 @@ public class GroupDatabase extends Database { return new Reader(null); } + if (recipientIds.size() > 30) { + Log.w(TAG, "[queryGroupsByMembership] Large set of recipientIds (" + recipientIds.size() + ")! Using the first 30."); + recipientIds = recipientIds.stream().limit(30).collect(Collectors.toSet()); + } + List recipientLikeClauses = recipientIds.stream() .map(RecipientId::toLong) .map(id -> "(" + MEMBERS + " LIKE " + id + " || ',%' OR " + MEMBERS + " LIKE '%,' || " + id + " || ',%' OR " + MEMBERS + " LIKE '%,' || " + id + ")")