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] matches = [-1]
return Annotation.objects.filter(id__in=matches) return Annotation.objects.filter(id__in=matches)
@transaction.commit_on_success @transaction.commit_on_success
def update_matches(self): def update_matches(self):
matches = self.get_matches() matches = self.get_matches()
@ -106,15 +105,21 @@ class Event(models.Model):
for i in self.annotations.exclude(id__in=matches): for i in self.annotations.exclude(id__in=matches):
self.annotations.remove(i) self.annotations.remove(i)
for i in matches.exclude(id__in=self.annotations.all()): 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])) ids = list(set([a.item.id for a in matches]))
for i in self.items.exclude(id__in=ids): for i in self.items.exclude(id__in=ids):
self.items.remove(i) self.items.remove(i)
for i in Item.objects.filter(id__in=ids).exclude(id__in=self.items.all()): 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:
#only update matches, other values might have been changed self.items.add(i)
if self.matches != numberofmatches: 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): def set_name_sort(self, value=None):
if not value: if not value:

View file

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

View file

@ -132,12 +132,15 @@ class Place(models.Model):
for i in self.annotations.exclude(id__in=matches): for i in self.annotations.exclude(id__in=matches):
self.annotations.remove(i) self.annotations.remove(i)
for i in matches.exclude(id__in=self.annotations.all()): 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])) ids = list(set([a.item.id for a in matches]))
for i in self.items.exclude(id__in=ids): for i in self.items.exclude(id__in=ids):
self.items.remove(i) self.items.remove(i)
for i in Item.objects.filter(id__in=ids).exclude(id__in=self.items.all()): 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 self.matches != numberofmatches:
if numberofmatches: if numberofmatches:
Place.objects.filter(id=self.id).update(matches=numberofmatches) Place.objects.filter(id=self.id).update(matches=numberofmatches)