Skip to content
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

[Viewer] Fetch users once per page #647

Merged
merged 1 commit into from
Apr 9, 2020
Merged

Conversation

fleupold
Copy link
Contributor

@fleupold fleupold commented Apr 9, 2020

We currently fetch the next user "on demand" whenever we exhaust the order for the current one. #641 noticed that the act of getting a single user is querying the size() of the allUser struct und thus actually iterates the list of all users in the system.

Consequently, getting all users is just twice as expensive as getting a single user (once for checking the size and once for getting them) mod the memory of storing them.

For a single unfiltered page we can have at most pageSize users (a user is only in the system if they have at least on order).

This PR therefore replaces the "fetch n times one user when needed" logic with "fetch once n users at the beginning" and then read the next user from that list.

Test Plan

No logic is changed (unit tests keep running). Notice, that now we can query the open orderbook with a page size of 1000 on a standard infura node:

npx truffle console --network mainnet

let instance = await BatchExchangeViewer.at("0xd7a78A333BAe9AAdDD5ebE41C209Fb5226eA155B")
let page = {nextPageUser: "0x0000000000000000000000000000000000000000", nextPageUserOffset:0}
page = await instance.contract.methods.getOpenOrderBookPaginated([], page.nextPageUser, page.nextPageUserOffset, 1000).call()
// ... continue last call until nextPage = false

@fleupold
Copy link
Contributor Author

fleupold commented Apr 9, 2020

Merging early as @fedgiac needs the new package version. If there is an issue with the code we can easily re-deploy.

@fleupold fleupold merged commit 8e82c74 into master Apr 9, 2020
fleupold added a commit that referenced this pull request Apr 9, 2020
Releasing #647 and #646 to the world...
@nlordell nlordell deleted the more_efficient_user_querying branch July 14, 2020 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants