如何防止两个用户同时编辑相同的内容 [英] how to prevent two user edit same content at same time

查看:141
本文介绍了如何防止两个用户同时编辑相同的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个多用户应用程序,其中,如果两个用户打开同一编辑页面,并且两个用户同时输入数据的形式将存在冲突数据,因此我需要一个解决方案,例如如果一个用户打开特定的编辑页面,那么所有另一位用户屏蔽了一段时间,并向他们提示一条消息,例如其他用户编辑同一页面...."

I made multi user application in which if two user open the same edit page and at the same time both user enter data in the form there would be conflict data so I need a solution like if one user open particular edit page then all other user block for some time and prompt a message to them like" other user edit the same page...."

推荐答案

也许

您可以在数据库"open"和"time"中添加两列

you could add two columns in your database 'open' and 'time'

如果有人正在编辑,则将"open"设置为"true"或"false". 还要在时间"列中设置一个时间戳.编辑时,每隔几秒钟就要更换一次时间戳.

Set 'open' to 'true' or 'false' if someone is editing it. Also set a timestamp to the 'time' column. Replace the timestamp every so many seconds while editing takes place.

如果其他人打开了它,请检查打开"列,然后将其设为"true",计算从时间"列中经过的时间. 如果超过一定时间(例如2或3分钟),请假定其他用户不再编辑,并允许该用户进行编辑.

If someone else opens it, check the 'open' column and of it's 'true', calculate the time passed from the 'time' column. If it's over a certain time (say 2 or 3 minutes), assume the other user isn't editing anymore and allow this user to edit.

为了弄清楚,

选项1:

  • 用户点击修改
  • 检查打开"列,如果它是"false",则将其设置为"true",然后将时间戳记添加到"time"
  • 只要用户在输入字段中键入内容,每10秒钟左右,就会进行一次AJAX调用,以使用当前时间戳更新时间"列.
  • 用户单击保存",打开"列设置为假". -
  • a user clicks on edit
  • check the 'open' column, if it's 'false', set it to 'true' and add the timestamp to 'time'
  • As long as the user is typing in the inputfield, every 10 seconds or so, an AJAX call is made to update the 'time' column with the present timestamp
  • user clicks 'save', the 'open' column is set to 'false'. -

选项2:

  • 用户点击修改
  • 检查打开"列,如果它是"true",则检查时间"列.
  • 如果与当前时间戳的差异超过(例如)2-3分钟,请允许对此用户进行编辑并更新时间戳.

这篇关于如何防止两个用户同时编辑相同的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆