fnp
/
wolnelektury.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
702b1be
)
bulk_create in update_popularity
author
Jan Szejko
<j-sz@o2.pl>
Tue, 16 Feb 2016 10:29:46 +0000
(11:29 +0100)
committer
Jan Szejko
<j-sz@o2.pl>
Tue, 16 Feb 2016 10:29:46 +0000
(11:29 +0100)
src/catalogue/management/commands/update_popularity.py
patch
|
blob
|
history
diff --git
a/src/catalogue/management/commands/update_popularity.py
b/src/catalogue/management/commands/update_popularity.py
index
3a99056
..
df9dedf
100644
(file)
--- a/
src/catalogue/management/commands/update_popularity.py
+++ b/
src/catalogue/management/commands/update_popularity.py
@@
-17,8
+17,10
@@
class Command(BaseCommand):
BookPopularity.objects.all().delete()
books_with_popularity = Book.objects.filter(tag_relations__tag__category='set').only('id').distinct()\
.annotate(pop=Count('tag_relations__tag__user', distinct=True))
BookPopularity.objects.all().delete()
books_with_popularity = Book.objects.filter(tag_relations__tag__category='set').only('id').distinct()\
.annotate(pop=Count('tag_relations__tag__user', distinct=True))
+ pop_list = []
for book in books_with_popularity:
for book in books_with_popularity:
-
BookPopularity.objects.create(book=book, count=book.pop
)
+
pop_list.append(BookPopularity(book=book, count=book.pop)
)
books_without_popularity = Book.objects.exclude(tag_relations__tag__category='set')
for book in books_without_popularity:
books_without_popularity = Book.objects.exclude(tag_relations__tag__category='set')
for book in books_without_popularity:
- BookPopularity.objects.create(book=book, count=0)
+ pop_list.append(BookPopularity(book=book, count=0))
+ BookPopularity.objects.bulk_create(pop_list, batch_size=512)