Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Implement storage extended Block - Closes #2698 #2711

Conversation

lsilvs
Copy link
Contributor

@lsilvs lsilvs commented Jan 8, 2019

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

const hasResult = expectedResultCount === 1 ? true : result.length > 0;

if (parsedOptions.extended && hasResult) {
const transactionStorage = new Transaction(this.adapter);
Copy link
Contributor

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.

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);
Copy link
Contributor

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.

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;
Copy link
Contributor

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.

Copy link
Contributor Author

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

}
}

return result;
Copy link
Contributor

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.

@MaciejBaj
Copy link
Contributor

Please fix the tests.

@nazarhussain
Copy link
Contributor

@LucasIsasmendi Please fix the tests so we can merge this PR.

@LucasIsasmendi
Copy link
Contributor

Maybe is for you @lsilvs

@nazarhussain nazarhussain merged commit 1835365 into feature/extensible-data-persistence-model Jan 8, 2019
@nazarhussain
Copy link
Contributor

@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.

@nazarhussain nazarhussain deleted the 2698-implement-extended-block branch January 8, 2019 15:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants