-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat: add pre-commit callbacks on EntityQueryContext #147
Conversation
Codecov Report
@@ Coverage Diff @@
## master #147 +/- ##
==========================================
+ Coverage 95.91% 95.94% +0.03%
==========================================
Files 74 74
Lines 1860 1874 +14
Branches 203 204 +1
==========================================
+ Hits 1784 1798 +14
Misses 75 75
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
seems useful 🆒
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.
I like your PR description and how you synthesized this solution from looking at recurring use cases.
LGTM but have some minor comments.
@@ -65,6 +79,17 @@ export class EntityTransactionalQueryContext extends EntityQueryContext { | |||
this.postCommitCallbacks.push(callback); | |||
} | |||
|
|||
public async runPreCommitCallbacksAsync(): Promise<void> { |
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.
IMO it's worth reaffirming one key thing in the documentation: the pre-commit callbacks are run according to their order (should we document that the order is stable otherwise? I'm thinking no, since if you care about the order of callbacks, you should express that with order
, not with the order in which they are registered).
Relatedly, do you think it is worth grouping callbacks by their order and running each group with Promise.all? (IMO: not that important right now, but may want to leave the API contract open to allow this, in which case we don't want to document that the callbacks are run serially -- just that they are run in order.)
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.
Good call. I think it's fine to not group them for now, but I'll update the documentation to indicate that it may be possible in the future.
Why
There are a lot of pieces of logic in our code that are similar in nature and contain all the following qualities:
Triggers unfortunately don't have the ability to specify when they should be run in relation to other triggers or during cascades (by design, I think, since it is tough to schedule cascading triggers). There are post-commit triggers/callbacks but those run outside the transaction.
How
Introduce a new concept, a "Pre-commit callback". These will run serially in the order specified by the application right before the transaction commits. If one throws, subsequent ones won't be run and the transaction will be rolled-back.
Test Plan
Run new tests.