Skip to content

Conversation

@rg911
Copy link
Contributor

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

@rg911 rg911 requested review from evias and fboucquez November 27, 2019 14:43
@coveralls
Copy link

coveralls commented Nov 27, 2019

Pull Request Test Coverage Report for Build 856

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 846: 0.0%
Covered Lines: 10
Relevant Lines: 10

💛 - Coveralls

Comment on lines 44 to 50
if (!this.networkType) {
networkTypeResolve = observableFrom(new NodeRoutesApi(this.url).getNodeInfo()).pipe(
map(({body}) => {
return body.networkIdentifier;
}),
catchError((error) => throwError(this.errorHandling(error))),
);
Copy link
Contributor

@fboucquez fboucquez Nov 28, 2019

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.

https://github.com/nemtech/nem2-sdk-java/blob/master/sdk-okhttp-client/src/main/java/io/nem/sdk/infrastructure/okhttp/RepositoryFactoryOkHttpImpl.java#L66

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

Copy link
Contributor Author

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.

@rg911 rg911 merged commit df4e16e into symbol:master Dec 2, 2019
@rg911 rg911 deleted the task/g361_network_in_http branch December 3, 2019 08:48
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.

4 participants