Corrected a problem with too many participants
This commit is contained in:
@@ -57,7 +57,7 @@ export async function getSpecificUsers(ids: string[]) {
|
||||
export async function getLinkedUsers(userID?: string, userType?: Type, type?: Type, firstID?: string, lastID?: string, size?: number) {
|
||||
const q = [
|
||||
...(!!type ? [where("type", "==", type)] : []),
|
||||
orderBy(documentId()),
|
||||
orderBy("registrationDate"),
|
||||
...(!!firstID && !lastID ? [endBefore(firstID)] : []),
|
||||
...(!!lastID && !firstID ? [startAfter(lastID)] : []),
|
||||
...(!!size ? [limit(size)] : []),
|
||||
@@ -87,19 +87,34 @@ export async function getLinkedUsers(userID?: string, userType?: Type, type?: Ty
|
||||
]);
|
||||
|
||||
// ⨯ [FirebaseError: Invalid Query. A non-empty array is required for 'in' filters.] {
|
||||
if(participants.length === 0) return {users: [], total: 0};
|
||||
if (participants.length === 0) return {users: [], total: 0};
|
||||
|
||||
const snapshot = await getDocs(query(collection(db, "users"), ...[where(documentId(), "in", participants), ...q]));
|
||||
if (participants.length < 30) {
|
||||
const snapshot = await getDocs(query(collection(db, "users"), ...[where(documentId(), "in", participants), ...q]));
|
||||
const users = snapshot.docs.map((doc) => ({
|
||||
id: doc.id,
|
||||
...doc.data(),
|
||||
})) as User[];
|
||||
|
||||
const total = await getCountFromServer(query(collection(db, "users"), ...[where(documentId(), "in", participants), ...totalQ]));
|
||||
|
||||
return {
|
||||
users,
|
||||
total: total.data().count,
|
||||
};
|
||||
}
|
||||
|
||||
const snapshot = await getDocs(query(collection(db, "users"), ...q));
|
||||
const users = snapshot.docs.map((doc) => ({
|
||||
id: doc.id,
|
||||
...doc.data(),
|
||||
})) as User[];
|
||||
|
||||
const total = await getCountFromServer(query(collection(db, "users"), ...[where(documentId(), "in", participants), ...totalQ]));
|
||||
const participantUsers = users.filter((x) => participants.includes(x.id));
|
||||
|
||||
return {
|
||||
users,
|
||||
total: total.data().count,
|
||||
users: participantUsers,
|
||||
total: participantUsers.length,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user