This question about Using an extension: Asked

Potential user conflict using set variable for Doc id in a topic

I am using the comment plugin together with the setvariableplugin to create a "reserve document id" form. The form is based on these tip Faq17 and BestPracticeTip1.

The form steps up a variable DOCID each time the user click OK in the form. However I see a problem during the following scenario:

Both user A and B have the same topic opened in their browsers. User A submit the form and the DOCID is stepped up by one. If then user B do the same without first doing a browser refresh, there will be a conflict where user B uses outdated topic data.

Does anyone know if there is a way to avoid this sceanrio?

-- AtleBriskemyr - 22 Feb 2010

I raised this concern in the BestPracticeTip1 topic. I don't think there are any easy solutions (other than using the AUTOINC feature, which I assume you have good reasons to avoid).

The easiest fix would be to create a perl plugin, as it seems a common enough request.

The other option is to live with non-sequential DOCIDs, ie. base them off a time or hash function.

Alternatively, you could write some javascript to trigger when the user presses OK (save); in doing so, blocks the save action from happening until an up-to-date (current) DOCID has been retrieved from the server, and incremented.

This method is still vulnerable to conflicting DOCIDs, but window for conflicts to occur is much smaller, only the few seconds it takes for the javascript to obtain current ID and the form being saved back to the server, instead of being vulnerable to conflicts for the entire duration that the user is working on a new topic.

-- PaulHarvey - 22 Feb 2010

Thanks for your suggestions.

With "The easiest fix would be to create a perl plugin", do you mean creating a plugin for that particular feature...?

I was thinking about using some kind of JavaScript. Since my DOCID is saved as meta data in the topic itself, I need to check if the topic have been updated, and if, then stop the save. I do not know if this is possible with js. Can 'inside topic' JavaScript do a another/new topic query?

-- AtleBriskemyr - 25 Feb 2010

Yes, I mean creating a perl plugin for this particular feature.

Anything is possible in Javascript, but I think this would be easiest:
  • Intercept the click on the save/submit button
  • Fetch current DOCID from wiki
  • Update the DOCID field in the form that we stopped from being submitted
  • Return to normal flow (now the browser POSTs/saves the new topic with an up-to-date DOCID).
This still has a small window of opportunity for conflicts to arise, but hopefully the window is only a few seconds in between the query to get the latest DOCID and the save which saves the new/incremented DOCID. If anybody else is trying to create a new DOCID at the same time there could be a conflict.

If you are happy with non-sequential DOCIDs there's also PermLinkPlugin

-- PaulHarvey - 03 Mar 2010

Hi!

Thanks for your answer. Your bullet-list suggestion, is exactly what I was hoping to accomplish with some javascript, but unfortunately I do not know enough about javascript. Tried to let Google help me, but came up with nothing. My problem is that I can't figure out how I can "Fetch current DOCID from wiki" with some javascript. The DOCID is a meta preference variable in the foswiki topic, so I need to query the topic itself.


Does anyone have some ideas on how to do this, or give me some hint on where to find some javascript examples for foswiki? Then I can start learning ... wink

-- AtleBriskemyr - 12 Mar 2010

Start putting the SEARCH and CALC stuff on an extra topic. Fetch this topic with params skin=text and cover=text via xhr in javascript...

This should output almost only your number without any skin stuff around.

-- OliverKrueger - 13 Mar 2010

QuestionForm edit

Subject Using an extension
Extension SetVariablePlugin
Version Foswiki 1.0.9
Status Asked
Topic revision: r7 - 13 Mar 2010, OliverKrueger
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy