Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Multiple, concurrent, session-scale transactions will generally lead to deadlocks or worse (worse == livelock, long delays while locks are held by another session.)</p> <p>This design is not the best policy, which is why Django discourages it.</p> <p>The better solution is the following.</p> <ol> <li><p>Design a <strong>Memento</strong> class that records the user's change. This could be a saved copy of their form input. You may need to record additional information if the state changes are complex. Otherwise, a copy of the form input may be enough.</p></li> <li><p>Accumulate the sequence of <strong>Memento</strong> objects in their session. Note that each step in the transaction will involve fetches from the data and validation to see if the chain of mementos will still "work". Sometimes they won't work because someone else changed something in this chain of mementos. What now?</p></li> <li><p>When you present the 'ready to commit?' page, you've replayed the sequence of <strong>Mementos</strong> and are pretty sure they'll work. When the submit "Commit", you have to replay the <strong>Mementos</strong> one last time, hoping they're still going to work. If they do, great. If they don't, someone changed something, and you're back at step 2: what now?</p></li> </ol> <p>This seems complex.</p> <p>Yes, it does. However it does not hold any locks, allowing blistering speed and little opportunity for deadlock. The transaction is confined to the "Commit" view function which actually applies the sequence of <strong>Mementos</strong> to the database, saves the results, and does a final commit to end the transaction.</p> <p>The alternative -- holding locks while the user steps out for a quick cup of coffee on step n-1 out of n -- is unworkable.</p> <p>For more information on <strong>Memento</strong>, see <a href="http://en.wikipedia.org/wiki/Memento_pattern" rel="nofollow noreferrer">this</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload