-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Refactoring method createTable #4456
Conversation
Replacing the weird task + transaction chain, by replacing it with just one transaction that encapsulates the complete logic.
correcting the sequence to match the original exactly.
Codecov Report
@@ Coverage Diff @@
## master #4456 +/- ##
==========================================
+ Coverage 92.68% 92.69% +0.01%
==========================================
Files 118 118
Lines 8348 8349 +1
==========================================
+ Hits 7737 7739 +2
+ Misses 611 610 -1
Continue to review full report at Codecov.
|
Nesting the transaction inside a task, so it can execute successfully no matter if the containing task succeeds or fails.
adding the missing bracket.
@flovilmart one more nailed 😉 |
@@ -684,6 +684,7 @@ export class PostgresStorageAdapter { | |||
// Just create a table, do not insert in schema | |||
createTable(className, schema, conn) { | |||
conn = conn || this._client; | |||
const self = this; |
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.
quick question, shouldn't we use .bind(this)
instead of self
capturing?
Not sure how it would work in that context... |
|
@vitaly-t but not required, I'm fine with the current implementation :) |
It is debatable. The thing is, methods The alternative approach, using the library's feature is to do But I just went for the simplest solution that's also known not to cause any conflict ;) |
// ELSE: Table already exists, must have been created by a different request. Ignore the error. | ||
} | ||
yield t.tx('create-table-tx', tx => { | ||
return tx.batch(relations.map(fieldName => { |
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.
@vitaly-t Merry Christmas. Quick question. I've notice you got rid of t.batch
in favor of t.none(this._pgp.helpers(...))
in other functions. Is there a reason why you use it here.
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.
@dplewis as per that PR, it is a performance optimization, to execute all queries via a single IO operation, as opposed to executing them separately. It is much faster that way ;)
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 always thought .batch
was a single I/O operation.
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.
Looks good to me 👍
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.
batch
is an operation irrelevant as to the IO, it simply resolves an array of promises, like Promise.all
does, except it also settles all the promises.
* Refactoring method createTable Replacing the weird task + transaction chain, by replacing it with just one transaction that encapsulates the complete logic. * Update PostgresStorageAdapter.js correcting the sequence to match the original exactly. * Update PostgresStorageAdapter.js Nesting the transaction inside a task, so it can execute successfully no matter if the containing task succeeds or fails. * Update PostgresStorageAdapter.js adding the missing bracket.
* Refactoring method createTable Replacing the weird task + transaction chain, by replacing it with just one transaction that encapsulates the complete logic. * Update PostgresStorageAdapter.js correcting the sequence to match the original exactly. * Update PostgresStorageAdapter.js Nesting the transaction inside a task, so it can execute successfully no matter if the containing task succeeds or fails. * Update PostgresStorageAdapter.js adding the missing bracket.
Replacing the needless task + transaction chain, by replacing it with just one transaction that encapsulates the complete logic.
Ended up having the transaction inside the task, to make it possible to execute the transaction when the task fails.