-
Notifications
You must be signed in to change notification settings - Fork 454
Implement storage extended Block - Closes #2698 #2711
Implement storage extended Block - Closes #2698 #2711
Conversation
storage/entities/block.js
Outdated
const hasResult = expectedResultCount === 1 ? true : result.length > 0; | ||
|
||
if (parsedOptions.extended && hasResult) { | ||
const transactionStorage = new Transaction(this.adapter); |
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 does not feel good to initiate object on every call. Either do it in constructor or somehow try to get it from parent storage object which holds the block entity itself.
storage/entities/block.js
Outdated
expectedResultCount === 1 ? [result.id] : result.map(({ id }) => id); | ||
const trxFilters = { blockId_in: blockIds }; | ||
const trxOptions = { limit: null, extended: true }; | ||
const transactions = await transactionStorage.get(trxFilters, trxOptions); |
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.
Pass the same tx
object here as well, so same DB transaction used for both.
storage/entities/block.js
Outdated
this.SQLs.select, | ||
params, | ||
{ expectedResultCount }, | ||
tx | ||
); | ||
|
||
// hasResult is always true when expectedResultCount == 1 because `executeFile` will throw an error otherwise | ||
const hasResult = expectedResultCount === 1 ? true : result.length > 0; |
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 expectedResultCount === 1
its always true
, it is possible to not find any result even for one object.
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.
If it doesn't find any pg-promise will throw an error.
Executes a query that expects exactly one row of data. When 0 or more than 1 rows are returned, the method rejects
ref.: http://vitaly-t.github.io/pg-promise/Database.html#one
storage/entities/block.js
Outdated
} | ||
} | ||
|
||
return result; |
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 not just treat everything as collection from start and just add condition expectedResultCount === 1
while returning.
Please fix the tests. |
@LucasIsasmendi Please fix the tests so we can merge this PR. |
Maybe is for you @lsilvs |
@lsilvs Integration tests are not running on this PR, please debug this issue and if there is any please fix it separately. All other tests are passing, so I merged the PR. |
What was the problem?
Blocks entity wasn't returning transactions
How did I fix it?
I've implemented extended block object which return transactions
How to test it?
storage.entities.Block.get({}, { extended: true });
Review checklist