防止两个用户编辑相同的数据 [英] Prevent two users from editing the same data

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

问题描述

我在不同的网络应用程序中看到了一个功能,包括Wordpress(不确定?),警告用户是否从数据库打开文章/文章/页面/任何东西,而其他人正在同时编辑相同的数据。

I have seen a feature in different web applications including Wordpress (not sure?) that warns a user if he/she opens an article/post/page/whatever from the database, while someone else is editing the same data simultaneously.

我想在我自己的应用程序中实现相同的功能,我给了这个想法。下面的例子是如何做到这一点的一个很好的做法?

I would like to implement the same feature in my own application and I have given this a bit of thought. Is the following example a good practice on how to do this?

它有点像这样:

1)用户A 输入神秘文章X的编辑页面。查询数据库表 Events 确保当时没有其他人正在编辑同一页面,那时没有人。然后随机生成一个令牌,并将其插入到一个名为 Events 的数据库表中。

1) User A enters a the editing page for the mysterious article X. The database tableEvents is queried to make sure that no one else is editing the same page for the moment, which no one is by then. A token is then randomly being generated and is inserted into a database table called Events.

1)用户B 也想要对文章X进行更新。由于我们的用户A 已经在编辑文章,所以事件查询,如下所示:

1) User B also want's to make updates to the article X. Now since our User A already is editing the article, the Events table is queried and looks like this:

|   timestamp   |   owner   |   Origin      |   token      |
------------------------------------------------------------
|   1273226321  |   User A  |   article-x   | uniqueid##   |

2)正在检查时间戳。如果它有效且不到100秒,则会出现一条消息,用户无法对所请求的文章进行任何更改X:

2) The timestamp is being checked. If it's valid and less than say 100 seconds old, a message appears and the user cannot make any changes to the requested article X:

Warning: User A is currently working with this article. In the meantime, editing cannot be done. Please do something else with your life.

3)如果用户A决定继续保存他的更改,其他数据以更新数据库,并切换查询以删除具有标记 uniqueid ## 的行。如果他决定做别的事而不是提交他的更改,则用户B

3) If User A decides to go on and save his changes, the token is posted along with all other data to update the database, and toggles a query to delete the row with token uniqueid##. If he decides to do something else instead of committing his changes, the article X will still be available for editing in 100 seconds for User B

让我知道你对这种方法的看法!

Let me know what you think about this approach!

祝大家一个伟大的周末!

Wish everyone a great weekend!

推荐答案

总是需要不到100秒?

Does editing an article always take less than 100 seconds ?

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

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