javascript - 我的 Firestore 中有超过 50,000 个文档,排序和查找的时间超过 30 秒,限制为 50 个。如何加快速度?

标签 javascript firebase react-native google-cloud-platform google-cloud-firestore

这是我在移动应用程序中使用的 React Native 的截图代码。我不能为了 50k 数据而等待 30 秒。想象一下加载 500k 或更多数据需要多长时间

useEffect(() => {
    const fetchData = () => {
      setLoading(true);
        firestore().collection('FData')
            .orderBy('counter', 'desc') //order using firestore counter
            .limit(50) //limiting value
            .onSnapshot(snapshot => { 
                var items = [];
                snapshot.forEach((doc)=> {
                    items.push({ id: doc.id, ...doc.data() });
                });
                setLoading(false);
                setList(items);
            })
    };
    fetchData();
}, []);

i have tried shifting the position of counter to the top but its also not working

最佳答案

您可以尝试在应用中对它们进行排序。 但我认为你的主要问题是 - 你试图通过一个请求获取 50k 件元素。实在是太多了10件就可以了。超过 100 - 不行。

关于javascript - 我的 Firestore 中有超过 50,000 个文档,排序和查找的时间超过 30 秒,限制为 50 个。如何加快速度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73873539/

相关文章:

javascript - 如何从 $(this) jQuery 对象中获取 this DOM 对象?

javascript - 我需要能够按下一个按钮来推特报价

javascript - 使用 waypoints.js 和 Anime.js 分别对具有相同类的元素进行动画处理

java - Firebase 未填充列表

Firebase - 可以创建多少个数据库?

javascript - jQuery:带有单引号的 td 内容在传递给模态时被 chop

ios - 使用 React Native 在 iOS 上下载文件

javascript - 将日期时间从一个偏移量转换为另一个偏移量

ios - 当显示在 FlatList 顶部时,OnPress 后背景颜色变为黑色

firebase - 使用未指定的索引。考虑添加 “.indexOn”: “g”