firebase - 递归获取用户列表 [Firebase + Saga]
问题描述
由于 Firebase 的 Firestore 在每个查询中只允许 10 个项目。我需要以 10 个用户为一组递归查询用户。
这是我从撰写 Sagas
中引用的内容,但users
返回了undefined
. 我做错了什么?或者是否有更好(更有效)的方式从 Firestore 查询用户列表?注意:我必须使用 Redux-Saga。
export function* watchGetListUsersByUids() {
yield takeEvery(USERS_GET_USERS_BY_UIDS, getListUsersByUids);
}
const getListUsersByUidsAsync = async (list_uid, set) => {
var get_uids = list_uid.slice(set * 10, (set + 1) * 10);
console.log("get_uids", get_uids);
await firestore
.collection("users")
.where("uid", "in", get_uids)
.get()
.then((data) => data.docs.map((doc) => doc.data()))
.catch((error) => error);
};
function* getListUsersByUids({ payload }) {
const { uids } = payload;
var numSet = parseInt(uids.length / 10);
var apiCalls = [];
for (var i = 0; i <= numSet; i++) {
apiCalls.push(call(getListUsersByUidsAsync, uids, i));
}
if (apiCalls.length) {
try {
const users = yield all(apiCalls);
console.log(users); // <-- [undefined, undefined, ...]
} catch (error) {
console.log(error);
}
}
}
解决方案
推荐阅读
- php - where column = NULL 和 whereNotIn 在 laravel 中不能一起工作
- javascript - Onclick 事件未按预期工作。知道为什么吗?
- perl - 如何查看特定 Perl 模块所需的所有模块?
- javascript - Web 音频 API - 获取 AudioContext 中源的当前时间
- python - 将数据框列中的整数值更改为字符串
- python - 计算所有行的特定列的元素出现次数
- scala - Spark将原始字节解组为可读格式
- html - 检查元素是否在视口中并获取元素 ID
- javascript - 我的 fetch 调用阻止了 Cookie
- css - 侧栏展开和折叠时的动态主