在客户端进行搜索而不是服务器端?

huangapple go评论72阅读模式
英文:

Searching on the client side instead of the server?

问题

半假设性的问题/想法在这里。

假设你有一个服务器,每隔X分钟(比如说30分钟)上传一个JSON文件,其中包含数据库表的内容之一。这个表不是太大,也许有2万个文档,每个文档有5-6个字段。它将这个文件放在一个公共目录中。

当用户进行搜索时,不是在服务器上执行查询,而是在客户端加载和搜索JSON文件,然后用相关的结果填充加载的网页。

一旦你点击一个结果,它会将你带到一个通常通过数据库加载的页面,提供最新的信息。

这种设置会有什么影响呢?在某些情况下,这种方式是否可行,可以减少数据库的重负载?每次从服务器获取JSON文件是否实际上对服务器的要求比直接使用数据库更大呢?

我期待听到你的想法 😊

英文:

Semi-hypothetical question/idea here.

Imagine you have a server that uploads a JSON file of one of its database tables’ contents every X amount of minutes, let’s say 30 for example. This table is not too large, maybe 20k docs with 5-6 fields each. It puts this in a public directory.

When a user searches, instead of performing a query on a server, it loads and searches the JSON file all on the client-side, then populates the loaded web page with any relevant results.

Once you click on a result, it takes you a page that is loaded normally via the database with up-to-date information.

What would the implications of this setup be? Would this actually be viable in some scenarios, to save on heavy database usage? Would fetching the JSON file from the server each time actually be more demanding to the server than just using a database?

I look forward to hearing your thoughts 😊

答案1

得分: 1

当然,你可以这样做,但这只是在某些客户端设备上才是一个合理的选择。

例如,如果客户端使用一部性能较差的老旧手机,让客户端下载20,000条记录,然后在查询时逐个处理这些记录可能会让应用程序对用户感觉非常迟缓(具体取决于查询的内容)。另一个问题是在小型设备上存储20,000条记录可能会成为一个问题。

客户端过滤在桌面设备上效果更好。桌面设备具有更强大的处理能力和更大的存储容量;IndexedDB 是一个常见的方法,用于在客户端存储大量信息。

但仅仅因为在某些情况下可能做到这一点,并不意味着这是一个的选择。在大多数情况下,专业的做法是让服务器进行所需的过滤工作,并将结果提供给客户端。如果服务器无法胜任自己的过滤任务,最好升级服务器。

英文:

Sure, you could do that, but it'd only be a reasonable choice on some client devices.

For example, if a client has a very old phone without a great processor, making the client download the 20k records and then go through each of them when making a query could make the app feel very sluggish to the user (depending on what exactly the query entails). Another issue is that storing 20k records on a small device could be a problem.

Client-side filtering would work better on desktops. Desktops have more power and more storage capacity; IndexedDB is a common approach used when a site wants to store a good deal of information on the client-side.

But just because it's possible in some circumstances doesn't mean that it's a good choice. In most situations, the professional approach would be to put the server to work to do the filtering needed, and to serve the results to clients. If the server isn't up to the task of filtering itself, you may as well upgrade the server.

huangapple
  • 本文由 发表于 2023年3月7日 11:09:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/75657705.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定