There is a database that stores large tables linked to users. If one user edits his table, then a flag is set in the database in order to prevent other users from opening this table (tables in the form of Excel are populated completely dynamically, as in Google Dox). If the user stops working with this table independently - presses the end button and goes to another section of the site, then everything is fine. If he simply closes the tab / forgets about the page and the session closes itself / goes from this tab to another site, then the flag remains set and I don’t know how to reset it.
- It is better to think about the mechanism of recording with history, as on Wikipedia or here, in SO. It is not good for a long time to block something. In general, you can make ajax which while the page is open every 30 seconds. for example, it sends to the server - I'm still editing. the server updates the local time in the database. if another user wants to open the table, look at the lock time, if more than 10 minutes, say, has not been updated, then the editor is lost, we can intercept the lock - Mike
- The fastest way I will do it, I will keep the time of using the table, then the binding to the user disappears. Thank. - Anton Braim
- oneOnly it is still crooked. I open the page for editing and go for tea. And then I get distracted by another browser window, without closing this one, and generally I go for a walk, but I never turn off the computer ... It can hang in a block like that for a month ... - Mike
- Not no, everything is normally implemented :)) the table is absolutely dynamic, that is, there is no button to save, all data is transferred under certain conditions immediately. I do not start updating the session, I just update the time in the database for this table with every transaction with the server. If the user is not active for more than half an hour, then the session flies and the user needs a relogin anyway (yes, everything is so difficult), respectively, starting from the session time, made a search and sorting of tables with the last update time plus half an hour :) - Anton Braim
- OMG, session is an extra dependency in this task. Where do you have a mark about the employment of a particular table? - artoodetoo
1 answer
The problem is akin to determining whether a user is online. The simplest solution without additional dependencies is to assume that the user has disconnected if there is no message from him for more than N seconds. That is, you need not a logical label Yes / No, but a value of type timestamp.
To keep this tag up to date, you will have to ping the javascript from the edit page every M <N seconds and update the tag on the server.
UPDATE : @Mike rightly pointed out in the comments that someone can leave the page open for a long time, and actually do nothing. This should not be a reason for blocking. So perhaps it is better not to "ping", but to update the employment label only with real changes. Or ping only if the user shows some activity on the page - to track keyboard events.
UPDATE 2nd and last : It's not about some session, but about the relevance of the system state. This is the answer to the question:
the flag remains set and I don’t know how to reset it
Instead of the mark "Иванов редактирует таблицу А"
, the mark "Иванов редактирует таблицу А"
should be kept "в 2015-01-23 10:34:55 Иванов редактирует таблицу А"
. And if the mark is too old, consider it irrelevant.
If you had once computed a list of users online, you would see an analogy.
- The problem is very weakly related to “finding the user online”, since each user can have at least 3x to infinity tables, and only editable should be forbidden to view. The table is a report for the year, respectively, even if the user has only 1 allocated space, then his table is scattered over the years, and each year is stored separately. Therefore, the solution proposed by Mike is optimal - to update the table with changes and not to update the session on the machine - Anton Braim
- It is a pity that they did not understand my offer. I did not mention any session at all. - artoodetoo
- Instead of clarifying the incomprehensible moments, you projected the proposal onto your knowledge base. It turned out garbage. - artoodetoo