From 29f852b57e5cdfec2184e498c30fe7537e027572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adeodato=20Sim=C3=B3?= Date: Fri, 26 Apr 2024 15:36:11 -0300 Subject: [PATCH 1/2] consolidate multiple cache.delete() calls into cache.delete_many() --- bookwyrm/models/book.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bookwyrm/models/book.py b/bookwyrm/models/book.py index 2e6377575..4ff377dbb 100644 --- a/bookwyrm/models/book.py +++ b/bookwyrm/models/book.py @@ -551,8 +551,12 @@ class Edition(Book): # clear author cache if self.id: - for author_id in self.authors.values_list("id", flat=True): - cache.delete(f"author-books-{author_id}") + cache.delete_many( + [ + f"author-books-{author_id}" + for author_id in self.authors.values_list("id", flat=True) + ] + ) @transaction.atomic def repair(self): From e6ee169c3e1dec189a2d7d34d66d2902ee327ac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adeodato=20Sim=C3=B3?= Date: Wed, 3 Apr 2024 20:36:40 -0300 Subject: [PATCH 2/2] Narrow down bare `type: ignore` pragmas --- bookwyrm/utils/db.py | 2 +- bookwyrm/utils/partial_date.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bookwyrm/utils/db.py b/bookwyrm/utils/db.py index fd2601deb..7024d9e47 100644 --- a/bookwyrm/utils/db.py +++ b/bookwyrm/utils/db.py @@ -1,7 +1,7 @@ """ Database utilities """ from typing import Optional, Iterable, Set, cast -import sqlparse # type: ignore +import sqlparse # type: ignore[import-untyped] def format_trigger(sql: str) -> str: diff --git a/bookwyrm/utils/partial_date.py b/bookwyrm/utils/partial_date.py index 4c9391476..d5b3cabc3 100644 --- a/bookwyrm/utils/partial_date.py +++ b/bookwyrm/utils/partial_date.py @@ -222,17 +222,17 @@ class PartialDateDescriptor: return [("DAY", "Day prec."), ("MONTH", "Month prec."), ("YEAR", "Year prec.")] -class PartialDateModel(models.DateTimeField): # type: ignore +class PartialDateModel(models.DateTimeField): # type: ignore[type-arg] """a date field for Django models, using PartialDate as values""" descriptor_class = PartialDateDescriptor - def formfield(self, **kwargs): # type: ignore + def formfield(self, **kwargs): # type: ignore[no-untyped-def] kwargs.setdefault("form_class", PartialDateFormField) return super().formfield(**kwargs) # pylint: disable-next=arguments-renamed - def contribute_to_class(self, model, our_name_in_model, **kwargs): # type: ignore + def contribute_to_class(self, model, our_name_in_model, **kwargs): # type: ignore[no-untyped-def] # Define precision field. descriptor = self.descriptor_class(self) precision: models.Field[Optional[str], Optional[str]] = models.CharField(