Skip to content

Commit

Permalink
datastore transactions: remove on ATProto.create_for, narrow in model…
Browse files Browse the repository at this point in the history
…s.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 #1376
  • Loading branch information
snarfed committed Oct 12, 2024
1 parent 93c034d commit 8b36e65
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
1 change: 0 additions & 1 deletion atproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 8b36e65

Please sign in to comment.