-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add transaction to event slots #233
base: main
Are you sure you want to change the base?
Add transaction to event slots #233
Conversation
More robust handling of mapping between origin and its hashed value
for more information, see https://pre-commit.ci
Thanks for the PR, I will have a look soon. |
if getattr(self, "_origin_hash", None) is not None: | ||
self._doc._origins.remove(cast(int, self._origin_hash)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why using getattr
, since _origin_hash
is set in __init__
?
@property | ||
def origin(self) -> Any: | ||
"""The origin of the transaction.""" | ||
return self._doc._origins.get(self._origin_hash) if self._origin_hash else None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not very likely, but since a hash is an int
it could be 0
.
return self._doc._origins.get(self._origin_hash) if self._origin_hash else None | |
return None if self._origin_hash is None else self._doc._origins.get(self._origin_hash) |
origin_hash = self._txn.origin() | ||
if origin_hash is not None: | ||
del self._doc._origins[origin_hash] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was a very deterministic behavior, why did you move that part to the transaction's __del__
method?
@fcollonval Could you explain the reasoning about adding a reference count to origins? |
Fixes #232
Fixes #234
Add transaction to event slots.
This ends up a bit more complex to be able to keep a reference to the transaction in the event, this PR introduced a
BaseTransaction
that only keeps reference to the document and the origin (independently of the rust object).That ensures the introspection of the event at any time.
It also introduces a more robust way to maintain the mapping of Python origin and rust origin.