summaryrefslogtreecommitdiffstats
path: root/users/models
diff options
context:
space:
mode:
authorAndrew Godwin2022-11-20 14:20:28 -0700
committerAndrew Godwin2022-11-20 14:20:28 -0700
commit6e88c0096942e008bb55d29b5696a058a2c1e013 (patch)
tree44ced82afa145b2dbeb8171d51998231d09607e1 /users/models
parent70d01bf1b4f44c48fa8af524ff7d73b485d62dc2 (diff)
downloadtakahe-6e88c0096942e008bb55d29b5696a058a2c1e013.tar.gz
takahe-6e88c0096942e008bb55d29b5696a058a2c1e013.tar.bz2
takahe-6e88c0096942e008bb55d29b5696a058a2c1e013.zip
Don't waste DB rows on bad inbox actors
Seems Sidekiq will keep trying to deliver messages even when the actor no longer exists?
Diffstat (limited to 'users/models')
-rw-r--r--users/models/identity.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/users/models/identity.py b/users/models/identity.py
index 510b947..c80d9d9 100644
--- a/users/models/identity.py
+++ b/users/models/identity.py
@@ -176,12 +176,17 @@ class Identity(StatorModel):
return None
@classmethod
- def by_actor_uri(cls, uri, create=False) -> "Identity":
+ def by_actor_uri(cls, uri, create=False, transient=False) -> "Identity":
try:
return cls.objects.get(actor_uri=uri)
except cls.DoesNotExist:
if create:
- return cls.objects.create(actor_uri=uri, local=False)
+ if transient:
+ # Some code (like inbox fetching) doesn't need this saved
+ # to the DB until the fetch succeeds
+ return cls(actor_uri=uri, local=False)
+ else:
+ return cls.objects.create(actor_uri=uri, local=False)
else:
raise cls.DoesNotExist(f"No identity found with actor_uri {uri}")
@@ -329,7 +334,8 @@ class Identity(StatorModel):
return False
if response.status_code == 410:
# Their account got deleted, so let's do the same.
- await Identity.objects.filter(pk=self.pk).adelete()
+ if self.pk:
+ await Identity.objects.filter(pk=self.pk).adelete()
return False
if response.status_code >= 400:
return False