Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Viewer] Fetch users once per page (#647)
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` ```js 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 ```
- Loading branch information