From 62a3891ecf18965641b2b59c67626f91d98cab35 Mon Sep 17 00:00:00 2001 From: Adam Kelly Date: Wed, 29 Apr 2020 16:13:09 +0100 Subject: [PATCH] Only import reviews if we're importing the book. (Avoid generating duplicate reviews.) --- fedireads/goodreads_import.py | 14 -------------- fedireads/outgoing.py | 11 +++++++++++ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/fedireads/goodreads_import.py b/fedireads/goodreads_import.py index 7d4abdd5..d88b4782 100644 --- a/fedireads/goodreads_import.py +++ b/fedireads/goodreads_import.py @@ -27,7 +27,6 @@ def import_data(job_id): job = ImportJob.objects.get(id=job_id) try: results = [] - reviews = [] for item in job.items.all(): try: item.resolve() @@ -36,24 +35,11 @@ def import_data(job_id): if item.book: item.save() results.append(item) - if item.rating or item.review: - reviews.append(item) else: item.fail_reason = "Could not match book on OpenLibrary" item.save() status = outgoing.handle_import_books(job.user, results) - for item in reviews: - review_title = "Review of {!r} on Goodreads".format( - item.book.title, - ) if item.review else "" - outgoing.handle_review( - job.user, - item.book, - review_title, - item.review, - item.rating, - ) if status: job.import_status = status job.save() diff --git a/fedireads/outgoing.py b/fedireads/outgoing.py index 19646e0c..717053a8 100644 --- a/fedireads/outgoing.py +++ b/fedireads/outgoing.py @@ -192,6 +192,17 @@ def handle_import_books(user, items): activity = activitypub.get_add(user, item.book, desired_shelf) broadcast(user, activity) + if item.rating or item.review: + review_title = "Review of {!r} on Goodreads".format( + item.book.title, + ) if item.review else "" + handle_review( + user, + item.book, + review_title, + item.review, + item.rating, + ) for read in item.reads: read.book = item.book read.user = user