avoid looking up item twice
This commit is contained in:
parent
7c53dca65b
commit
22f83288c5
3 changed files with 11 additions and 8 deletions
|
@ -434,7 +434,7 @@ class Item(models.Model):
|
||||||
a.public_id = public_id
|
a.public_id = public_id
|
||||||
a.save()
|
a.save()
|
||||||
if sync:
|
if sync:
|
||||||
tasks.update_file_paths(self.public_id)
|
self.update_file_paths()
|
||||||
if update_poster:
|
if update_poster:
|
||||||
tasks.update_poster(self.public_id)
|
tasks.update_poster(self.public_id)
|
||||||
else:
|
else:
|
||||||
|
@ -1099,6 +1099,11 @@ class Item(models.Model):
|
||||||
else:
|
else:
|
||||||
self.update_facet(key)
|
self.update_facet(key)
|
||||||
|
|
||||||
|
def update_file_paths(self):
|
||||||
|
for f in item.files.all():
|
||||||
|
if f.normalize_path() != f.path:
|
||||||
|
f.save()
|
||||||
|
|
||||||
def path(self, name=''):
|
def path(self, name=''):
|
||||||
h = self.public_id
|
h = self.public_id
|
||||||
h = (7-len(h))*'0' + h
|
h = (7-len(h))*'0' + h
|
||||||
|
|
|
@ -67,9 +67,7 @@ def update_poster(public_id):
|
||||||
@task(ignore_results=True, queue='default')
|
@task(ignore_results=True, queue='default')
|
||||||
def update_file_paths(public_id):
|
def update_file_paths(public_id):
|
||||||
item = models.Item.objects.get(public_id=public_id)
|
item = models.Item.objects.get(public_id=public_id)
|
||||||
for f in item.files.all():
|
item.update_file_paths()
|
||||||
if f.normalize_path() != f.path:
|
|
||||||
f.save()
|
|
||||||
|
|
||||||
@task(ignore_results=True, queue='default')
|
@task(ignore_results=True, queue='default')
|
||||||
def update_external(public_id):
|
def update_external(public_id):
|
||||||
|
|
|
@ -15,8 +15,8 @@ def update_itemsort(id):
|
||||||
|
|
||||||
@task(ignore_results=True, queue='default')
|
@task(ignore_results=True, queue='default')
|
||||||
def update_file_paths(id):
|
def update_file_paths(id):
|
||||||
from item.models import Item
|
from item.models import Item, ItemFind
|
||||||
from item.tasks import update_file_paths
|
|
||||||
p = models.Person.objects.get(pk=id)
|
p = models.Person.objects.get(pk=id)
|
||||||
for i in Item.objects.filter(find__value__icontains=p.name).distinct():
|
items = ItemFind.objects.filter(key='name', value__icontains=p.name).values('item_id')
|
||||||
update_file_paths(i.public_id)
|
for i in Item.objects.filter(id__in=items):
|
||||||
|
i.update_file_paths()
|
||||||
|
|
Loading…
Reference in a new issue