avoid parallel updates to matches

This commit is contained in:
j 2012-01-13 16:47:42 +05:30
parent 4e6c2250c9
commit 265d3d5bcd
3 changed files with 17 additions and 9 deletions

View file

@ -98,7 +98,6 @@ class Event(models.Model):
matches = [-1]
return Annotation.objects.filter(id__in=matches)
@transaction.commit_on_success
def update_matches(self):
matches = self.get_matches()
@ -106,15 +105,21 @@ class Event(models.Model):
for i in self.annotations.exclude(id__in=matches):
self.annotations.remove(i)
for i in matches.exclude(id__in=self.annotations.all()):
self.annotations.add(i)
#need to check again since editEvent might have been called again
if self.annotations.filter(id=i.id).count() == 0:
self.annotations.add(i)
ids = list(set([a.item.id for a in matches]))
for i in self.items.exclude(id__in=ids):
self.items.remove(i)
for i in Item.objects.filter(id__in=ids).exclude(id__in=self.items.all()):
self.items.add(i)
#only update matches, other values might have been changed
if self.items.filter(id=i.id).count() == 0:
self.items.add(i)
if self.matches != numberofmatches:
Event.objects.filter(id=self.id).update(matches=numberofmatches)
if numberofmatches:
Event.objects.filter(id=self.id).update(matches=numberofmatches)
else:
self.matches = numberofmatches
self.save()
def set_name_sort(self, value=None):
if not value:

View file

@ -292,14 +292,14 @@
"title": "Saturation",
"type": "float",
"columnWidth": 90,
"format": {"type": "color", "args": ["greyscale"]}
"format": {"type": "color", "args": ["saturation"]}
},
{
"id": "lightness",
"title": "Lightness",
"type": "float",
"columnWidth": 90,
"format": {"type": "color", "args": ["greyscale"]}
"format": {"type": "color", "args": ["lightness"]}
},
{
"id": "volume",

View file

@ -132,12 +132,15 @@ class Place(models.Model):
for i in self.annotations.exclude(id__in=matches):
self.annotations.remove(i)
for i in matches.exclude(id__in=self.annotations.all()):
self.annotations.add(i)
#need to check again since editEvent might have been called again
if self.annotations.filter(id=i.id).count() == 0:
self.annotations.add(i)
ids = list(set([a.item.id for a in matches]))
for i in self.items.exclude(id__in=ids):
self.items.remove(i)
for i in Item.objects.filter(id__in=ids).exclude(id__in=self.items.all()):
self.items.add(i)
if self.items.filter(id=i.id).count() == 0:
self.items.add(i)
if self.matches != numberofmatches:
if numberofmatches:
Place.objects.filter(id=self.id).update(matches=numberofmatches)