From 45ddce36aa15bb32a2a168cdd034aa0ff6771d4f Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Sun, 21 Jan 2024 00:31:07 -0500 Subject: [PATCH] Look in DB for book first --- vrobbler/apps/books/models.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/vrobbler/apps/books/models.py b/vrobbler/apps/books/models.py index a1224ca..0996ebb 100644 --- a/vrobbler/apps/books/models.py +++ b/vrobbler/apps/books/models.py @@ -269,11 +269,14 @@ class Book(LongPlayScrobblableMixin): @classmethod def find_or_create(cls, lookup_id: str, author: str = "") -> "Book": - data = lookup_book_from_openlibrary(lookup_id, author) + book = cls.objects.filter(openlibrary_id=lookup_id).first() - book, book_created = cls.objects.get_or_create(isbn=data["isbn"]) - if book_created: - book.fix_metadata(data=data) + if not book: + data = lookup_book_from_openlibrary(lookup_id, author) + + book, book_created = cls.objects.get_or_create(isbn=data["isbn"]) + if book_created: + book.fix_metadata(data=data) return book