On Nov 2, 2007, at 7:48 AM, Matthew Newhook wrote:

>
> Sorry for the continuing post spam... However, I think I know what is
> causing this problem. What tipped me off is I am seeing multiple
> copies of the same item in my shopping cart if I really hammer at the
> "add cart" button (instead of a single item with a quantity > 1). Each
> of these are an AJAX call and therefore I think can processed prior to
> the previous call returning. What happens is:
> - I load the shopping cart (and other stuff)
> - I start a transaction
> - I check to see if the item is already in the cart. If its there I
> increment the quantity, if not I add a new item to the cart.
> - I commit the transaction
>
> What can I suspect is the addCart can be called concurrently -- the
> transaction protects the database lock, but not the now cached data in
> the in-memory model. This also likely caused the removeCart issue that
> occurs above since it probably results in removing the same cart item
> twice causing an error when one of them is flushed to the database.
>
> So what is the correct solution here? I don't think that mutex
> protection of the cart model itself will work as each copy of the cart
> is presumably a new copy of the underlying data. I could, of course,
> protect the actual addCart and removeCart method in the web server (as
> opposed to the model). However, that sucks since it precludes multi-
> threaded access to separate carts which should be possible.
>

this would seem to me like it should be fixed at the ajax level, or  
possibly the level of the webserver where it receives ajax events.   
your ajax functionality constitutes a GUI, and most GUIs I've worked  
with have a single "event queue" whereby all events are serialized  
into a single stream.  the nature of the XMLHttpRequest is  
asynchronous so it seems like either your ajax library would have to  
delay the second ajax request until the first one completes, or the  
web server would have to enforce similar behavior (probably easier on  
the ajax side).


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to