如何保持服务器和浏览器之间的队列同步?
我有一个表(代表一个项目队列),其行可以使用 jQuery 可排序插件重新排序。用户可以对队列进行重新排序,更新后的顺序会保存到服务器上。
我面临的挑战是服务器定期从队列顶部拉出一个项目,对其进行处理,然后将其移动到队列底部。发生这种情况时,用户在浏览器上看到的顺序已过时,当他们尝试重新排序时,索引会变得混乱。
我提出了几个解决方案来解决这个问题,但我不太确定从可用性的角度来看什么交互才有意义。我考虑过检测 UI 上的拖动事件并首先检查服务器上的更新,但如果我刷新页面,那么用户正在进行的拖动将会被中断。
我知道服务器何时会更新队列,因此我考虑轮询此信息,然后在更新发生前几秒钟锁定拖动功能,然后更新顺序并解锁拖动功能。
我很好奇以前是否有人解决过类似的问题。任何想法或指导将不胜感激。
I have a table (which represents a queue of items) whose rows can be reordered using the jQuery sortable plugin. A user can reorder their queue and the updated order saves to the server fine.
The challenge I face is that the server periodically pulls an item off the top of queue, process it, then move it to the bottom of the queue. When this happens, the order that the user sees on the browser is outdated and when they try to reorder, the indexes get all messed up.
I've come up with a couple solutions to solve this problem, but I'm not quite sure what interaction would make sense from a usability perspective. I've considered detecting the drag event on the UI and checking for updates on the server first, but if I refresh the page, then the dragging that the user was in the middle of would be interrupted.
I know when the server will update the queue, so I considered polling for this information, then locking down the dragging functionality a few seconds before the update occurs, then updating the order and unlocking the drag functionality.
I'm curious if anyone has solved a similar issue before. Any ideas or guidance would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决此问题的常用方法是使用 Ajax 定期(大约 10 秒)刷新页面。如果客户端状态过时,您应该通知用户并恢复客户端状态以与服务器同步。可以通过多种方式实现恢复:最简单的方法是拒绝客户端的更改并使用服务器的状态进行更新。更难的是尝试将客户端状态与服务器状态合并,这更有用。
The usual approach to this problem is to periodically (in order of about 10 seconds maybe) refresh the page partially using Ajax. If it happens that the client state is outdated, you should inform the user and recover the client state to be synchronized with the server's. The recovery can be achieved in multiple ways: The easiest would be to just refuse the client's changes and update with the server's state. The harder would be to try to merge the client state with the server's, which is way more usable.
定期分页是可行的方法,但我要补充一点,如果没有任何更改,您可能不想对表进行更新。也许在您的记录中保存“上次更新”字段并检查上次更新是否> >最后一页尝试是一个解决方案。
Periodic paging is the way to go, but I'd add that you probably don't want to do an update on the table if nothing has changed. Perhaps saving a "last updated" field on your records and checking to see if last updated > last page attempt is a solution.