Merge pull request #2741 from WesleyAC/optimize-csv-export-query
Optimize CSV export query
This commit is contained in:
commit
6f1e80be60
1 changed files with 13 additions and 10 deletions
|
@ -22,16 +22,19 @@ class Export(View):
|
||||||
|
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
"""Download the csv file of a user's book data"""
|
"""Download the csv file of a user's book data"""
|
||||||
books = (
|
books = models.Edition.viewer_aware_objects(request.user)
|
||||||
models.Edition.viewer_aware_objects(request.user)
|
books_shelves = books.filter(Q(shelves__user=request.user)).distinct()
|
||||||
.filter(
|
books_readthrough = books.filter(Q(readthrough__user=request.user)).distinct()
|
||||||
Q(shelves__user=request.user)
|
books_review = books.filter(Q(review__user=request.user)).distinct()
|
||||||
| Q(readthrough__user=request.user)
|
books_comment = books.filter(Q(comment__user=request.user)).distinct()
|
||||||
| Q(review__user=request.user)
|
books_quotation = books.filter(Q(quotation__user=request.user)).distinct()
|
||||||
| Q(comment__user=request.user)
|
|
||||||
| Q(quotation__user=request.user)
|
books = set(
|
||||||
)
|
list(books_shelves)
|
||||||
.distinct()
|
+ list(books_readthrough)
|
||||||
|
+ list(books_review)
|
||||||
|
+ list(books_comment)
|
||||||
|
+ list(books_quotation)
|
||||||
)
|
)
|
||||||
|
|
||||||
csv_string = io.StringIO()
|
csv_string = io.StringIO()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue