commit
2140631e74
|
@ -619,10 +619,11 @@ class Work(models.Model):
|
|||
@property
|
||||
def googlebooks_id(self):
|
||||
preferred_id=self.preferred_edition.googlebooks_id
|
||||
# note that there's always a preferred edition
|
||||
if preferred_id:
|
||||
return preferred_id
|
||||
try:
|
||||
return self.identifiers.values('type', 'value').filter(type='goog')[0]['value']
|
||||
return self.identifiers.filter(type='goog')[0].value
|
||||
except IndexError:
|
||||
return ''
|
||||
|
||||
|
@ -639,7 +640,7 @@ class Work(models.Model):
|
|||
if preferred_id:
|
||||
return preferred_id
|
||||
try:
|
||||
return self.identifiers.values('type', 'value').filter(type='gdrd')[0]['value']
|
||||
return self.identifiers.filter(type='gdrd')[0].value
|
||||
except IndexError:
|
||||
return ''
|
||||
|
||||
|
@ -650,7 +651,7 @@ class Work(models.Model):
|
|||
@property
|
||||
def librarything_id(self):
|
||||
try:
|
||||
return self.identifiers.values('type', 'value').filter(type='ltwk')[0]['value']
|
||||
return self.identifiers.filter(type='ltwk')[0].value
|
||||
except IndexError:
|
||||
return ''
|
||||
|
||||
|
@ -661,7 +662,7 @@ class Work(models.Model):
|
|||
@property
|
||||
def openlibrary_id(self):
|
||||
try:
|
||||
return self.identifiers.values('type', 'value').filter(type='olwk')[0]['value']
|
||||
return self.identifiers.filter(type='olwk')[0].value
|
||||
except IndexError:
|
||||
return ''
|
||||
|
||||
|
|
|
@ -52,6 +52,8 @@ class BookLoaderTests(TestCase):
|
|||
|
||||
# work
|
||||
self.assertTrue(edition.work)
|
||||
self.assertEqual(edition.work.googlebooks_id, 'IDFfMPW32hQC')
|
||||
self.assertEqual(edition.work.first_isbn_13(), '9780441007462')
|
||||
|
||||
# publisher names
|
||||
old_pub_name = edition.publisher_name
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
from django.core.management.base import BaseCommand
|
||||
from django.contrib.auth.models import User
|
||||
from datetime import timedelta
|
||||
import datetime
|
||||
from regluit.core import models
|
||||
|
||||
num=0
|
||||
start = datetime.datetime.now()
|
||||
for work in models.Work.objects.all():
|
||||
try:
|
||||
id = work.identifiers.values('type', 'value').filter(type='goog')[0]['value']
|
||||
except IndexError:
|
||||
pass
|
||||
num += 1
|
||||
if num == 10000:
|
||||
break
|
||||
end = datetime.datetime.now()
|
||||
print "2 values "+str(end - start)
|
||||
|
||||
num=0
|
||||
start = datetime.datetime.now()
|
||||
for work in models.Work.objects.all():
|
||||
try:
|
||||
id = work.identifiers.filter(type='goog')[0].value
|
||||
except IndexError:
|
||||
pass
|
||||
num += 1
|
||||
if num == 10000:
|
||||
break
|
||||
end = datetime.datetime.now()
|
||||
print "orig "+str(end - start)
|
||||
|
||||
num=0
|
||||
start = datetime.datetime.now()
|
||||
for work in models.Work.objects.all():
|
||||
try:
|
||||
id = work.identifiers.values('value').filter(type='goog')[0]['value']
|
||||
except IndexError:
|
||||
pass
|
||||
num += 1
|
||||
if num == 10000:
|
||||
break
|
||||
end = datetime.datetime.now()
|
||||
print "1 value "+ str(end - start)
|
||||
|
||||
num=0
|
||||
start = datetime.datetime.now()
|
||||
for work in models.Work.objects.all():
|
||||
try:
|
||||
id = work.identifiers.values('type', 'value').filter(type='goog')[0]['value']
|
||||
except IndexError:
|
||||
pass
|
||||
num += 1
|
||||
if num == 10000:
|
||||
break
|
||||
end = datetime.datetime.now()
|
||||
print "2 values "+str(end - start)
|
Loading…
Reference in New Issue