简体   繁体   English

如何在基于 webpack-react-node 的网站中处理非常大的数据(100000 个 javascript 对象)?

[英]How do I handle very large data (100000 javascript objects) in webpack-react-node based website?

I have a react-node based website in which I need to work on a dataset close to 100000 javascript objects, all objects containing the same set of keys.我有一个基于 react-node 的网站,我需要在其中处理接近 100000 个 javascript 对象的数据集,所有对象都包含相同的键集。 Various functionalities have to be implemented like display suggestions on searching by name, sorting, filtering, all of which need to be as fast as instantaneous.必须实现各种功能,例如显示按名称搜索、排序、过滤的建议,所有这些都需要尽可能快。

There are a few options which I thought of:我想到了几个选项:

1.) Storing all the data in a relational database (SQL) with keys as the column name.

v/s

2.) Storing all the data in a non-relational database (MongoDB) as an array of objects.

v/s

3.) Storing all the data in a .js file in the server as `export const data={Array-Of_Objects}`

In the functionality in which when input is typed in a search box, suggestions are shown, I think that I can't keep going back to the database to fetch all the objects and then perform processing to find best suggestions as soon as a letter is typed to maintain fast functionality.在搜索框中输入输入时显示建议的功能中,我认为我不能继续返回数据库获取所有对象,然后在收到字母后立即执行处理以找到最佳建议键入以保持快速功能。

Hence, I decided to follow the third option but still, the .js file containing all the data is close to 100 MB and importing the data using const {data}= require(./file.js) is not happening, let alone processing and finding the best suggestions, which happens when I reduce the data size from 100000 objects to (say) 5000 objects.因此,我决定遵循第三个选项,但包含所有数据的 .js 文件仍然接近 100 MB,并且没有使用const {data}= require(./file.js)导入数据,更不用说处理了并找到最佳建议,当我将数据大小从 100000 个对象减少到(比如)5000 个对象时,就会发生这种情况。

If I divide all the data into various .js files and import them separately, I think still the importing of all the files and the processing of data will not be fast enough.如果我把所有的数据分成各种.js文件单独导入,我觉得还是所有文件的导入和数据的处理都不够快。

Please suggest me what is the best method to follow or free technology to use.请建议我遵循或免费使用技术的最佳方法是什么。

The best way according to me would be have them stored in DB(MongoDB or RDBMS) and implement lazy loading don't import data in React component it will cause performance issue because Dom Tree will be heavy in that case and if any changes in data will take time to compare which node is changed.我认为最好的方法是将它们存储在 DB(MongoDB 或 RDBMS)中并实现延迟加载不要在 React 组件中导入数据,这将导致性能问题,因为在这种情况下 Dom 树会很重,如果数据有任何更改需要时间来比较哪个节点发生了变化。

Still if you don't want to use any DB i'll suggest use json-server here you can store the data in a single file and then make rest call to get the data and do the manipulation in redux, here as well you can go with lazy loading.尽管如此,如果您不想使用任何数据库,我建议您在这里使用json-server您可以将数据存储在单个文件中,然后进行休息调用以获取数据并在 redux 中进行操作,在这里您也可以使用延迟加载。

You are just storing data somewhere(DB,js file) how you are going to access data and display in component performance matters there if you have 100000 javascript object am sure you are not going to display all of them at a time so better filter it in redux and only pass the data which will be usefull to component.您只是将数据存储在某处(DB,js 文件)如果您有 100000 个 javascript 对象,您将如何访问数据并在组件性能中显示很重要,请确保您不会一次显示所有这些对象,以便更好地过滤它在 redux 中,只传递对组件有用的数据。

Things are working now.现在一切正常。 I am accessing the data from the backend from the database as soon as the user presses first 2-3 character.一旦用户按下第一个 2-3 个字符,我就会从数据库的后端访问数据。 The result thus obtained is of lower size than the complete database.这样得到的结果比完整的数据库小。 And then from the next request onward I am filtering the last results in javascript itself.然后从下一个请求开始,我将过滤 javascript 本身中的最后一个结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM