如何存储大量数据

发布于 2025-02-01 19:30:41 字数 742 浏览 2 评论 0原文

我必须从API中获得 5MB JSON文件 https:/ /pi.sleeper.app/v1/players/nfl ),但是由于他的尺寸需要一段时间,但是我只需要每天一次获得此文件。因此,我的问题是:有一种将此文件存储在我的应用中的方法,并且当我必须尝试使用​​ASYNC存储和一些使用相同逻辑的软件包时,请在我的应用中获取一些内容,但是<强>异步请求只需提取函数

我想要的是以一种快速操纵这些数据的方式,而不是每次都需要我需要一些作品。

现在,我正在使用由我自己制作的API,该API占用此5MB文件并返回我需要的特定片段( https://teste-draft.netlify.app/.netlify/functions/getPlayersData?name = 167 )。但是,这个临时解决方案的问题是,当我必须获得很多播放器(例如20岁甚至更多的玩家)时,因为这么多请求,因此该应用程序最终需要很长时间才能显示数据。

I have to get a 5MB json file from an API (https://api.sleeper.app/v1/players/nfl), but because of his size the fetch take a while, but I just need to get this file once a day. So, my question is: theres a way to storage this file inside my app and get some piece when I have to? I've tried Async Storage and some others packages that uses the same logic, but the async request takes as long as the fetch function.

What I want is some way to manipulate this data in a fast way than if a have to fetch every single time that I need some piece.

Right now I'm using an API made by my own which takes this 5MB file and return the specific piece that I need (https://teste-draft.netlify.app/.netlify/functions/getplayersdata?name=167). But the problem with this temporary solution is when I have to get a lot of players (like 20 or even more), because it's so many requests that the app ends up taking a long time to display the data.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鲜肉鲜肉永远不皱 2025-02-08 19:30:41

我通过创建一个上下文来存储所有5 MB数据,在用户打开应用程序时将获取这一点。这并不是我想要的,因为当用户关闭整个应用程序时,每次都可以运行。

import { useState, createContext, useEffect } from "react"

export const AllPlayersContext = createContext()

export const AllPlayersContextProvider = ({children}) => {
    const [allPlayers, setAllPlayers] = useState(null)

    const getAllPlayers = () => {
        console.log('Getting players...')
        const URL = `https://api.sleeper.app/v1/players/nfl`;
        fetch(URL)
        .then(response => response.json())
        .then(data => {
            setAllPlayers(data)
        }).catch((e) => {
            console.log('Error:', e)
        })
    }

    useEffect(() => {
        getAllPlayers()
    },[])

    if(!allPlayers){
        return (
          <Loading />
        )
      }


    return ( 
        <AllPlayersContext.Provider value={{allPlayers}}>
        {children}
        </AllPlayersContext.Provider>
     );
}
 

I solved this by creating a Context to store all the 5 MB data, to be fetched when the user open the app. It was not exactly what I wanted, because the fetch run every time when the user close the entire app, but worked...

import { useState, createContext, useEffect } from "react"

export const AllPlayersContext = createContext()

export const AllPlayersContextProvider = ({children}) => {
    const [allPlayers, setAllPlayers] = useState(null)

    const getAllPlayers = () => {
        console.log('Getting players...')
        const URL = `https://api.sleeper.app/v1/players/nfl`;
        fetch(URL)
        .then(response => response.json())
        .then(data => {
            setAllPlayers(data)
        }).catch((e) => {
            console.log('Error:', e)
        })
    }

    useEffect(() => {
        getAllPlayers()
    },[])

    if(!allPlayers){
        return (
          <Loading />
        )
      }


    return ( 
        <AllPlayersContext.Provider value={{allPlayers}}>
        {children}
        </AllPlayersContext.Provider>
     );
}
 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文