forked from 0x2620/pandora
avoid parallel updates to matches
This commit is contained in:
parent
4e6c2250c9
commit
265d3d5bcd
3 changed files with 17 additions and 9 deletions
|
@ -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()):
|
||||||
|
#need to check again since editEvent might have been called again
|
||||||
|
if self.annotations.filter(id=i.id).count() == 0:
|
||||||
self.annotations.add(i)
|
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()):
|
||||||
|
if self.items.filter(id=i.id).count() == 0:
|
||||||
self.items.add(i)
|
self.items.add(i)
|
||||||
#only update matches, other values might have been changed
|
|
||||||
if self.matches != numberofmatches:
|
if self.matches != numberofmatches:
|
||||||
|
if numberofmatches:
|
||||||
Event.objects.filter(id=self.id).update(matches=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:
|
||||||
|
|
|
@ -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",
|
||||||
|
|
|
@ -132,11 +132,14 @@ 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()):
|
||||||
|
#need to check again since editEvent might have been called again
|
||||||
|
if self.annotations.filter(id=i.id).count() == 0:
|
||||||
self.annotations.add(i)
|
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()):
|
||||||
|
if self.items.filter(id=i.id).count() == 0:
|
||||||
self.items.add(i)
|
self.items.add(i)
|
||||||
if self.matches != numberofmatches:
|
if self.matches != numberofmatches:
|
||||||
if numberofmatches:
|
if numberofmatches:
|
||||||
|
|
Loading…
Reference in a new issue