Skip to content

Instantly share code, notes, and snippets.

@JensRantil
Last active May 22, 2016 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JensRantil/822fccc1eba9cd74907b4855e1f77513 to your computer and use it in GitHub Desktop.
Save JensRantil/822fccc1eba9cd74907b4855e1f77513 to your computer and use it in GitHub Desktop.
Create an observable that fetches smaller batches of users based on prefix
class UserLister {
...
public Observable<User> streamAll(int batchSize) {
final int prefixLength = estimatePrefixLength(batchSize);
Preconditions.checkState(prefixLength > 0);
log.debug("Estimated prefix length: " + prefixLength);
return Observable.from(RepositoryUtils.hexPrefixes(prefixLength)).flatMapIterable(new Function1<String, List<User>>() {
public List<User> call(String prefix) {
repository.listByIdPrefix(useridPrefix);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment