简体   繁体   English

在NodeJS中搜索前端vs后端

[英]Searching at frontend vs backend in NodeJS

I am developing a web application using NodeJS & SailsJS frameworks. 我正在使用NodeJS和SailsJS框架开发Web应用程序。 Now I am going to develop searching functionality. 现在我要开发搜索功能。 There are around 5000 records from which I want to search on one attribute. 我想要在一个属性上搜索大约5000条记录。

I know I can search it using mogodb query. 我知道我可以使用mogodb查询进行搜索。 What if I get all the records in javascript at frontend and search from it? 如果我在前端获取javascript中的所有记录并从中搜索该怎么办? What is good way to search? 什么是搜索的好方法? At backend using db query or at fronend using javascript searching? 在后端使用数据库查询或在fronend使用javascript搜索?

If you search in the frontend then you have to load the entire dataset into the frontend and keep it synchronised for every query. 如果在前端进行搜索,则必须将整个数据集加载到前端,并使其与每个查询保持同步。 This is not a good idea. 这不是一个好主意。

Use database queries - that is what they are designed for, and you only need to transfer the results. 使用数据库查询 - 这是它们的设计目标,您只需要传输结果。

It's all about your app. 这都是关于你的应用程序。 If you have set of data around 50K items it could work on the client fluently. 如果您有大约50K项目的数据集,它可以在客户端流畅地工作。 And it could be faster. 它可能会更快。 But It's better to test on real data. 但是测试真实数据会更好。

Advantages: 好处:

  • fast queries: no network latency. 快速查询:没有网络延迟。
  • simple queries: query can use JS with engine optimization advantages. 简单查询:查询可以使用JS与引擎优化的优点。

Disadvantages: 缺点:

  • load full dataset (critical on huge amounts of data). 加载完整数据集(对大量数据至关重要)。
  • require synchronization strategy: full reload, partial updates, CRDT, etc. 需要同步策略:完全重新加载,部分更新,CRDT等。

Do it in backend only using db query, which is good practice.It will reduce execution time. 仅使用db查询在后端执行,这是一种很好的做法。它将减少执行时间。

Should not do this kind of check in client side as you have to send the whole database to client and loop through the records several times to fetch the desired records. 不应该在客户端进行这种检查,因为您必须将整个数据库发送到客户端并多次遍历记录以获取所需的记录。

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

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