From 482005f3049ba8a1c533983f5751b18e1f6ba3fe Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Sun, 5 Jun 2022 20:03:36 +0000 Subject: [PATCH] Update preview image generation to only query ids Previously we were querying the full book objects just to get a list of id's, which is much slower and also takes a lot more memory, which can cause the process to be killed on memory-limited machines with a large number of books. Instead, since we're just dispatching jobs here, we can just ask for the id's, which is faster and much more practical memory-wise. The map is a little annoying, I didn't see a way to directly get just a list of the value of one field, so we have to get a list of dictionairies with one key and then pull that key out. Whatevs. --- bookwyrm/management/commands/generate_preview_images.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bookwyrm/management/commands/generate_preview_images.py b/bookwyrm/management/commands/generate_preview_images.py index 0454e5e5..b00fafb1 100644 --- a/bookwyrm/management/commands/generate_preview_images.py +++ b/bookwyrm/management/commands/generate_preview_images.py @@ -56,12 +56,12 @@ class Command(BaseCommand): self.stdout.write(" OK 🖼") # Books - books = models.Book.objects.select_subclasses().filter() + book_ids = [values["id"] for values in models.Book.objects.select_subclasses().filter().values('id')] self.stdout.write( - " → Book preview images ({}): ".format(len(books)), ending="" + " → Book preview images ({}): ".format(len(book_ids)), ending="" ) - for book in books: - preview_images.generate_edition_preview_image_task.delay(book.id) + for book_id in book_ids: + preview_images.generate_edition_preview_image_task.delay(book_id) self.stdout.write(".", ending="") self.stdout.write(" OK 🖼")