-
Notifications
You must be signed in to change notification settings - Fork 57
Task/g361 network in http #362
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
Conversation
rg911
commented
Nov 27, 2019
- Added optional para 'NetworkType' to Http to bypass Rest calls for retrieving networkType.
- Tested on NamespaceHttp.spec.ts in e2e
| if (!this.networkType) { | ||
| networkTypeResolve = observableFrom(new NodeRoutesApi(this.url).getNodeInfo()).pipe( | ||
| map(({body}) => { | ||
| return body.networkIdentifier; | ||
| }), | ||
| catchError((error) => throwError(this.errorHandling(error))), | ||
| ); |
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.
Every time getNetworkTypeObservable is called a new NodeRoutesApi is created and the rest endpoint is called. This is not very efficient and it may ban the server. I would move the networkTypeResolve to a read-only field and create it up in the constructor. If cached, the user has less need for hard-coding the network type in the constructor and leaves the HTTPs to handle the network type efficiently.
Java has an observable.cache method to cache the result in memory.
Once we have the factory, the cache will work much better as the cached value will be reused between multiple Http Objects (Transaction, Account, etc...).
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.
Can put the refactoring into a separate sdk refactor task. Also the cash would probably be better to put into the implementation e.g. client wallet etc to be able to provide more control.