perf: smarter transactions and authorization for built-in actions #1347
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Performance improvements on built-in actions
Summary:
create
: reduced from 5 to 2 - 5 db hitsupdate
: reduced from 6 to 2 - 4 db hitsdelete
: reduced from 6 to 2 - 4 db hitsSmarter authorization
For all action types, we perform better early authorization checks, which means we can avoid unnecessary database hits when row-based permissions aren't being used. For
create
, we even avoid the use of transactions entirely.Typically, this is the order of database events (i.e. incurring a DB 'hit') for an built-in
create
action:a) open transaction
b) execute create statement
c) perform row-based permissions query
d) commit (or rollback) transaction
That is FOUR hits to the database, which is expensive especially when no row-based permissions are even performed.
Now we check if transaction and row-based permission checks are even needed. If they aren't needed, then the action will be reduced to a single query - executing the insert statement without a transaction block
No more transactions on
update
anddelete
Furthermore, transactions were only in place on
update
anddelete
as a fail safe if multiple rows happened to be affected (which would be an error on Keel's part). We have so many tests and I think the risk of this happening is so low. The cost of a transaction for every single action call is quite high, so I've opted for dropping it.