use transaction.atomic

This commit is contained in:
j 2016-02-19 21:55:09 +05:30
parent e738503380
commit e22cc432b3
13 changed files with 19 additions and 19 deletions

View File

@ -38,7 +38,7 @@ class Command(BaseCommand):
for i in range(len(annotations)-1):
if annotations[i]['out'] == annotations[i+1]['in']:
annotations[i]['out'] = annotations[i]['out'] - 0.001
with transaction.commit_on_success():
with transaction.atomic():
for a in annotations:
if a['value']:
annotation = models.Annotation(

View File

@ -160,7 +160,7 @@ class Annotation(models.Model):
self.sortvalue = None
self.languages = None
with transaction.commit_on_success():
with transaction.atomic():
if not self.clip or self.start != self.clip.start or self.end != self.clip.end:
self.clip, created = Clip.get_or_create(self.item, self.start, self.end)
@ -184,7 +184,7 @@ class Annotation(models.Model):
update_matches(self.id, 'event')
def delete(self, *args, **kwargs):
with transaction.commit_on_success():
with transaction.atomic():
super(Annotation, self).delete(*args, **kwargs)
if self.clip and self.clip.annotations.count() == 0:
self.clip.delete()

View File

@ -113,7 +113,7 @@ def update_item(id, force=False):
#cleanup orphaned clips
Clip.objects.filter(item__id=a.item.id, annotations__id=None).delete()
#update facets if needed
with transaction.commit_on_success():
with transaction.atomic():
if filter(lambda f: f['id'] == a.layer and f.get('filter'), settings.CONFIG['itemKeys']):
a.item.update_layer_facet(a.layer)
Item.objects.filter(id=a.item.id).update(modified=a.modified)
@ -129,7 +129,7 @@ def update_item(id, force=False):
def update_annotations(layers, value):
items = {}
with transaction.commit_on_success():
with transaction.atomic():
for a in models.Annotation.objects.filter(
layer__in=layers,
value=value

View File

@ -101,7 +101,7 @@ class Edit(models.Model):
index = self.clips.count()
ids = [i['id'] for i in self.clips.order_by('index').values('id')]
added = []
with transaction.commit_on_success():
with transaction.atomic():
for data in clips:
c = self.add_clip(data)
if c:
@ -116,7 +116,7 @@ class Edit(models.Model):
def sort_clips(self, ids):
index = 0
with transaction.commit_on_success():
with transaction.atomic():
for i in ids:
Clip.objects.filter(id=i).update(index=index)
index += 1

View File

@ -148,7 +148,7 @@ def orderClips(request, data):
if edit.editable(request.user):
if edit.type == 'static':
index = 0
with transaction.commit_on_success():
with transaction.atomic():
for i in ids:
models.Clip.objects.filter(edit=edit, id=i).update(index=index)
index += 1

View File

@ -196,7 +196,7 @@ class Entity(models.Model):
entity = get_by_id(settings.CONFIG['entities'], self.type)
if not entity:
return
with transaction.commit_on_success():
with transaction.atomic():
ids = ['name']
for key in entity['keys']:
value = self.data.get(key['id'])

View File

@ -84,7 +84,7 @@ class Event(models.Model):
def get_super_matches(self):
return get_super_matches(self, Event)
@transaction.commit_on_success
@transaction.atomic
def update_matches(self, annotations=None):
matches = self.get_matches(annotations)
if not annotations:

View File

@ -17,7 +17,7 @@ class Command(BaseCommand):
def handle(self, id, height, position, **options):
position = float(position)
height = int(height)
with transaction.commit_on_success():
with transaction.atomic():
i = models.Item.objects.get(public_id=id)
path = i.frame(position, height)
if path:

View File

@ -769,7 +769,7 @@ class Item(models.Model):
return titles
with transaction.commit_on_success():
with transaction.atomic():
for key in settings.CONFIG['itemKeys']:
i = key['id']
if i == 'title':
@ -1547,7 +1547,7 @@ class Item(models.Model):
# only import on 0xdb for now or if forced manually
# since this will remove all existing subtitles
if force or not existing.count() or settings.USE_IMDB:
with transaction.commit_on_success():
with transaction.atomic():
Annotation.objects.filter(layer=layer, item=self).delete()
AnnotationSequence.reset(self)
offset = 0
@ -1790,7 +1790,7 @@ class AnnotationSequence(models.Model):
@classmethod
def nextid(cls, item):
with transaction.commit_on_success():
with transaction.atomic():
s, created = cls.objects.get_or_create(item=item)
if created:
nextid = s.value

View File

@ -32,7 +32,7 @@ def update_random_sort():
def update_random_clip_sort():
if filter(lambda f: f['id'] == 'random', settings.CONFIG['itemKeys']):
with transaction.commit_on_success():
with transaction.atomic():
cursor = connection.cursor()
cursor.execute('DROP TABLE clip_random;')
cursor.execute('CREATE TABLE "clip_random" AS SELECT id AS clip_id, row_number() OVER (ORDER BY random()) AS random FROM "clip_clip"')

View File

@ -149,7 +149,7 @@ def addListItems(request, data):
list = get_list_or_404_json(data['list'])
if 'items' in data:
if list.editable(request.user):
with transaction.commit_on_success():
with transaction.atomic():
for item in Item.objects.filter(public_id__in=data['items']):
list.add(item)
response = json_response(status=200, text='items added')
@ -208,7 +208,7 @@ def orderListItems(request, data):
response = json_response()
if list.editable(request.user) and list.type == 'static':
index = 0
with transaction.commit_on_success():
with transaction.atomic():
for i in data['ids']:
models.ListItem.objects.filter(list=list, item__public_id=i).update(index=index)
index += 1

View File

@ -96,7 +96,7 @@ class Place(models.Model):
def get_super_matches(self):
return get_super_matches(self, Place)
@transaction.commit_on_success
@transaction.atomic
def update_matches(self, annotations=None):
matches = self.get_matches(annotations)
if not annotations:

View File

@ -122,7 +122,7 @@ def signout(request, data):
profile.save()
response = json_response(text='logged out')
logout(request)
with transaction.commit_on_success():
with transaction.atomic():
for s in Session.objects.all():
if s.get_decoded().get('_auth_user_id') == uid:
s.delete()