本文介绍了实时与非事件编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用 crossrider 制作一个浏览器插件来同步书签,但由于没有在新书签上"事件,我如何将所有上传的新书签同步到服务器并实时更新其他连接机器上的书签列表?我倾向于使用 websocket 来做到这一点,但正如我所说,它不是基于事件的.那么我每 n 秒轮询一次所有客户端吗?这似乎有很多数据被移动,并且似乎对服务器造成负担,因为该过程可能包括:首先每 n 秒请求所有客户端书签,然后将它们与客户端记录的书签列表进行比较,如果发生匹配,更新客户端浏览器的书签.简而言之,解决这个难题的最佳方法是什么?

I am currently trying to make a browser plugin using crossrider that will sync bookmarks but as there is no "on new bookmark" event how do I sync all upload new bookmarks to the server and update bookmarks lists on other connected machines in realtime? I would be inclined to do this with a websocket but as I said it is not event based. So do I poll all the clients every n seconds? That seems like a lot of data being moved and it seems taxing on the server as the process presumably wold include: first requesting all the clients bookmarks every n seconds and then comparing them to a list of the clients logged bookmars and, in the event of a match, update the clients browser's bookmarks. So in short, what is the best solution to the conundrum?

推荐答案

鉴于你描述的场景,我认为投票是最好的解决方案.

Given the scenario you describe, I think that polling it the best solution.

如果我正确理解了您的扩展程序的意图,那么我会做的一件事是您比较书签的方式.在您的解决方案中,您提到将书签数据发送到服务器、比较并将数据发送回客户端以更新浏览器书签.

If I correctly understand the intention of your extension, the one thing I would do differently is how you compare the bookmarks. In your solution, you mention sending the bookmarks data to the server, comparing, and sending data back to the client to update the browser bookmarks.

我认为更好更有效的解决方案是在客户端比较书签并将新书签发送到服务器.您可以存储书签快照,以便在使用我们的本地数据库 appAPI 进行比较时使用.db.async API 和我们的 appAPI.request API 发送新书签到您的服务器.

I think a better more efficient solution would be to compare the bookmarks on the client-side and send new bookmarks to the server. You can store a snapshot of the bookmarks for use when comparing using our local database appAPI.db.async API and our appAPI.request API to send the new bookmarks to your server.

我们 Crossrider 会随时帮助您解决您可能遇到的任何问题.因此,如果您需要任何帮助,请随时联系我们的支持团队 (support@crossrider.com).

We at Crossrider are here to help you with any issues or questions you might have. Hence, if you need any assistance, please do not hesitate to contact our support (support@crossrider.com).

免责声明:我是 Crossrider 员工.

Disclaimer: I am a Crossrider employee.

这篇关于实时与非事件编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 01:24
查看更多