requesting optimized
This commit is contained in:
parent
e2e4c47871
commit
2e3cd8fcd5
|
|
@ -26,7 +26,6 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
import rx.internal.util.RxRingBuffer;
|
|
||||||
import rx.subjects.PublishSubject;
|
import rx.subjects.PublishSubject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -51,34 +50,11 @@ public abstract class ItemsProvider<T> {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Observable<List<T>> loadRange(final int first, final int last) {
|
public Observable<List<T>> loadRange(final int first, final int last) {
|
||||||
final List<Observable<List<T>>> itemsRequests = new ArrayList<>();
|
final List<Observable<T>> itemsRequests = new ArrayList<>();
|
||||||
|
for (int i = first; i <= last; i++) {
|
||||||
int index = first;
|
itemsRequests.add(loadItem(i));
|
||||||
while (index <= last) {
|
|
||||||
final List<Observable<T>> limitedPageRequests = new ArrayList<>();
|
|
||||||
final int maxIndex = index + RxRingBuffer.SIZE - 1;
|
|
||||||
while (index <= Math.min(last, maxIndex)) {
|
|
||||||
limitedPageRequests.add(loadItem(index));
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
itemsRequests.add(Observable.combineLatest(limitedPageRequests, args -> {
|
|
||||||
final List<T> resultPart = new ArrayList<>(args.length);
|
|
||||||
for (final Object item : args) {
|
|
||||||
if (item != null) {
|
|
||||||
resultPart.add((T) item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return resultPart;
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
return Observable.concatEager(itemsRequests).toList();
|
||||||
return Observable.combineLatest(itemsRequests, args -> {
|
|
||||||
final List<T> result = new ArrayList<>();
|
|
||||||
for (final Object resultPart : args) {
|
|
||||||
result.addAll((List<T>) resultPart);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue