On Sun, 25 Sep 2011 02:09:46 +0200, Russell Keith-Magee <russ...@keith-magee.com> wrote:

On Sat, Sep 24, 2011 at 10:08 PM, Martin Tiršel <dja...@blackpage.eu> wrote:
Hello,

I am using Apache with mod_wsgi and following setting:

WSGIDaemonProcess dev.xyz.com processes=1 threads=5 user=xyz group=xyz
display-name=dev.xyz.com

I am observing some situations where a user sends the same request multiple times (double click?) where the time between these requests is very low -
80-100ms. Then I got these situations (bot request from the same user):

1. request A - SELECT ...
2. request B - SELECT ...
3. request A - INSERT ... (insert is based on select result from step 1)
4. request B - INSERT ... (insert is based on select result from step 2)

Because 1. and 2. gets the same data, I end with doubled (or sometimes
trippled) inserts what breaks my application. How do you prevent such
behaviour? I am using Django 1.2.x

I might be missing something obvious here, but isn't this *exactly*
what database transactions are designed to fix? Admittedly, you've got
an unusual presentation born out of weird browser behavior, but making
sure that two overlapping operations don't violate data integrity
sounds like the textbook case for using transactions.

Yours,
Russ Magee %-)


In my case, I have a construction_queue which has an order, building_level, game_base_id and some other fields. Order field is for sorting the queue. When I am inserting new item, i need to determine values for order and building_level. Order field is from SELECT COUNT... and building_level from built_buildings plus number of buildings of the same name in construction_queue. So when double request load the same data, the same inserts are created. Transaction would be usable when I add unique index on game_base_id with order. In that case when double request comes, I got an exception and I can rollback the second request. You mean it this way?

Martin

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to