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) {
|
export async function getLinkedUsers(userID?: string, userType?: Type, type?: Type, firstID?: string, lastID?: string, size?: number) {
|
||||||
const q = [
|
const q = [
|
||||||
...(!!type ? [where("type", "==", type)] : []),
|
...(!!type ? [where("type", "==", type)] : []),
|
||||||
orderBy(documentId()),
|
orderBy("registrationDate"),
|
||||||
...(!!firstID && !lastID ? [endBefore(firstID)] : []),
|
...(!!firstID && !lastID ? [endBefore(firstID)] : []),
|
||||||
...(!!lastID && !firstID ? [startAfter(lastID)] : []),
|
...(!!lastID && !firstID ? [startAfter(lastID)] : []),
|
||||||
...(!!size ? [limit(size)] : []),
|
...(!!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.] {
|
// ⨯ [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) => ({
|
const users = snapshot.docs.map((doc) => ({
|
||||||
id: doc.id,
|
id: doc.id,
|
||||||
...doc.data(),
|
...doc.data(),
|
||||||
})) as User[];
|
})) 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 {
|
return {
|
||||||
users,
|
users: participantUsers,
|
||||||
total: total.data().count,
|
total: participantUsers.length,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user