From b457446f2ff69f850e927ae40e4bb025c3d9c260 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 22 Apr 2021 19:36:27 -0700 Subject: [PATCH] Don't save duplicate boosts --- bookwyrm/models/activitypub_mixin.py | 6 ++---- bookwyrm/models/status.py | 8 ++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bookwyrm/models/activitypub_mixin.py b/bookwyrm/models/activitypub_mixin.py index 2e248fbe3..02cfafc0e 100644 --- a/bookwyrm/models/activitypub_mixin.py +++ b/bookwyrm/models/activitypub_mixin.py @@ -204,10 +204,8 @@ class ObjectMixin(ActivitypubMixin): created = created or not bool(self.id) # first off, we want to save normally no matter what super().save(*args, **kwargs) - if ( - not broadcast - or hasattr(self, "status_type") - and self.status_type == "Announce" + if not broadcast or ( + hasattr(self, "status_type") and self.status_type == "Announce" ): return diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 360288e93..65bf71d28 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -351,6 +351,14 @@ class Boost(ActivityMixin, Status): def save(self, *args, **kwargs): """ save and notify """ + # This constraint can't work as it would cross tables. + # class Meta: + # unique_together = ('user', 'boosted_status') + if Boost.objects.filter( + boosted_status=self.boosted_status, user=self.user + ).exists(): + return + super().save(*args, **kwargs) if not self.boosted_status.user.local or self.boosted_status.user == self.user: return