From 8b36e6527d0debee8524fde9575963280ed7eee5 Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Fri, 11 Oct 2024 21:09:47 -0700 Subject: [PATCH] datastore transactions: remove on ATProto.create_for, narrow in models.enable we were doing heavy work like generating RSA keys and external network requests for creating DIDs inside datastore txes, which led to bad contention. details in https://github.com/snarfed/bridgy-fed/issues/1376 --- atproto.py | 1 - models.py | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/atproto.py b/atproto.py index 4b50f803..98b43fb5 100644 --- a/atproto.py +++ b/atproto.py @@ -367,7 +367,6 @@ def is_blocklisted(url, allow_internal=False): return util.domain_or_parent_in(util.domain_from_link(url), DOMAIN_BLOCKLIST) @classmethod - @ndb.transactional() def create_for(cls, user): """Creates an ATProto repo and profile for a non-ATProto user. diff --git a/models.py b/models.py index 12c744d0..f740b316 100644 --- a/models.py +++ b/models.py @@ -537,6 +537,9 @@ def enable_protocol(self, to_proto): """ added = False + if to_proto.LABEL in ids.COPIES_PROTOCOLS and not self.get_copy(to_proto): + to_proto.create_for(self) + @ndb.transactional() def enable(): user = self.key.get() @@ -547,9 +550,6 @@ def enable(): nonlocal added added = True - if to_proto.LABEL in ids.COPIES_PROTOCOLS and not user.get_copy(to_proto): - to_proto.create_for(user) - return user new_self = enable()