mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 19:41:11 +00:00
Optimize CSV export query
Splitting this into five separate queries avoids the large join that prevents us from using indexes, and requires materializing to disk. Fixes: #2157 (hopefully)
This commit is contained in:
parent
ded3f469ef
commit
60fee54da9
1 changed files with 13 additions and 10 deletions
|
@ -22,16 +22,19 @@ class Export(View):
|
|||
|
||||
def post(self, request):
|
||||
"""Download the csv file of a user's book data"""
|
||||
books = (
|
||||
models.Edition.viewer_aware_objects(request.user)
|
||||
.filter(
|
||||
Q(shelves__user=request.user)
|
||||
| Q(readthrough__user=request.user)
|
||||
| Q(review__user=request.user)
|
||||
| Q(comment__user=request.user)
|
||||
| Q(quotation__user=request.user)
|
||||
)
|
||||
.distinct()
|
||||
books = models.Edition.viewer_aware_objects(request.user)
|
||||
books_shelves = books.filter(Q(shelves__user=request.user)).distinct()
|
||||
books_readthrough = books.filter(Q(readthrough__user=request.user)).distinct()
|
||||
books_review = books.filter(Q(review__user=request.user)).distinct()
|
||||
books_comment = books.filter(Q(comment__user=request.user)).distinct()
|
||||
books_quotation = books.filter(Q(quotation__user=request.user)).distinct()
|
||||
|
||||
books = set(
|
||||
list(books_shelves)
|
||||
+ list(books_readthrough)
|
||||
+ list(books_review)
|
||||
+ list(books_comment)
|
||||
+ list(books_quotation)
|
||||
)
|
||||
|
||||
csv_string = io.StringIO()
|
||||
|
|
Loading…
Reference in a new issue