监控用户会话prevent编辑冲突冲突、编辑、用户、prevent

2023-09-10 13:19:09 作者:指尖蓓蕾.

我的工作类似一个引擎收录(是的,它的是的泛型),但允许多个用户编辑。的明显的问题是多个用户尝试编辑同一文件的。我沿着锁定,当一个用户正在使用它的文件的行思(这不是最好的解决办法,但我什么都不需要太复杂),但prevent /警告用户我想显然需要一个系统,用于监视每个用户的编辑会话。与数据库和Ajax的工作,我正在考虑两种解决方案。

I'm working on something similar to a pastebin (yeah, it's that generic) but allowing for multiple user editing. The obvious problem is that of multiple users attempting to edit the same file. I'm thinking along the lines of locking down the file when one user is working on it (it's not the best solution, but I don't need anything too complex), but to prevent/warn the user I'd obviously need a system for monitoring each user's edit sessions. Working with database and ajax, I'm thinking of two solutions.

第一是有编辑页面ping服务器,在任意时间间隔,比如一分钟,将更新的数据库编辑会话表项。那么下一次的脚本要求编辑,它会检查最新的ping,如果最近​​的一次是另一种任意的时间前,例如五分钟,然后再我们假设previous用户已经quited和文件即可再次编辑。当然,用这种方法的问题是,使previous用户已经quited的假设是一个简单的假设。他可以有片状的Wi-Fi连接,只是退出了十分钟,所有的时间与窗口仍处于打开状态。

The first would be to have the edit page ping the server at a arbitrary interval, say a minute, and it would update the edit session entry in the db. Then the next time a script request to edit, it checks for the most recent ping, and if the most recent was another arbitrary time ago, say five minute, then we assume that the previous user had quited and the file can be edited again. Of course, the problem with this method is that the assumption that the previous user had quited is simply an assumption. He could be having flaky wi-fi connection and simply dropped out for ten minutes, all the time with the window still open.

当然,要处理的这个的问题,我们就必须有从previously闭门会议的新要求与错误的服务器响应,告诉客户端指出,以他会话已结束,然后处理它由用户,说,保存为在服务器上的另一文件,并要求用户手动合并它等,不用说,这是相当可怕的最终用户。

Of course, to deal with this problem, we'd have to have the server respond to new request from previously closed sessions with an error, telling the client side to point out to the user that his session has ended, and then deal with it by, say, saving it as another file on the server and asking the user to manually merge it, etc. It goes without saying that this is rather horrible for the end user.

所以我到来的时候想到的另一种解决方案。它也有可能获得一个卸载事件给用户的会话结束时闪光,但我不能肯定这是否会可靠地工作。

So I've came around to think of another solution. It may also be possible to get a unload event to fire when the user's session ends, but I cannot be sure whether this will work reliably.

是否有人有任何其他更好的解决这个问题?

Does anybody has any other, more elegant solution to this problem?

推荐答案

如果您预计并发编辑的数量,该文件是次要的,你可以只存储一个版本号在数据库中的文件,当用户将该文件下载到他们的浏览器,他们也得到了版本号。他们只允许上传自己的变化,如果版本号相匹配。第一个上传的胜利。当检测到一个冲突就发送回最新的文件和用户的改动,使得用户可以在改变手工合并。的优点是,这个工程即使它的同一用户使两个同时编辑。如果此功能最终被经常使用,你可以添加客户端融合类似于一个diff工具使用(但你可能需要保留旧版本在这种情况下)。

If you expect the number of concurrent edits to the file to be minor, you could just store a version number for the file in the db, and when the user downloads the file into their browser they also get the version number. They are only allowed to upload their changes if the version number matches. First one to upload wins. When a conflict is detected you should send back the latest file and the user's changes so that the user can manually merge in the changes. The advantage is that this works even if it's the same user making two simultaneous edits. If this feature ends up being frequently used you could add client-side merging similar to what a diff tool uses (but you might need to keep the old revisions in that case).