Skip to content

Commit e45b281

Browse files
committed
handle comparison values more than 30 for in clause
1 parent 107e9e2 commit e45b281

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

models/users.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,21 +181,34 @@ const fetchPaginatedUsers = async (query) => {
181181
const fetchFilteredUsers = async (usernames = []) => {
182182
try {
183183
const dbQuery = userModel;
184+
const filterdUsersWithDetails = [];
184185

185-
const snapshot = await dbQuery.where("github_id", "in", usernames).get();
186+
const groups = [];
187+
const batchSize = 30; // since only 30 comparisons are allowed with the 'in' clause
188+
for (let i = 0; i < usernames.length; i += batchSize) {
189+
groups.push(usernames.slice(i, i + batchSize));
190+
}
186191

187-
const filterdUsersWithDetails = [];
192+
// For each group, write a separate query
193+
const promises = groups.map((group) => {
194+
return dbQuery.where("github_id", "in", group).get();
195+
});
188196

189-
snapshot.forEach((doc) => {
190-
filterdUsersWithDetails.push({
191-
id: doc.id,
192-
...doc.data(),
193-
phone: undefined,
194-
email: undefined,
195-
tokens: undefined,
196-
chaincode: undefined,
197+
const snapshots = await Promise.all(promises);
198+
199+
snapshots.forEach((snapshot) => {
200+
snapshot.forEach((doc) => {
201+
filterdUsersWithDetails.push({
202+
id: doc.id,
203+
...doc.data(),
204+
phone: undefined,
205+
email: undefined,
206+
tokens: undefined,
207+
chaincode: undefined,
208+
});
197209
});
198210
});
211+
199212
return {
200213
filterdUsersWithDetails,
201214
};

0 commit comments

Comments
 (0)