Skip to content

Commit

Permalink
Parallelize issue loading API requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Fs00 authored and maniac103 committed Sep 10, 2021
1 parent 439c0d6 commit 256692e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app/src/main/java/com/gh4a/fragment/IssueFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.List;

import io.reactivex.Single;
import io.reactivex.schedulers.Schedulers;
import retrofit2.Response;

public class IssueFragment extends IssueFragmentBase {
Expand Down Expand Up @@ -77,13 +78,15 @@ protected Single<List<TimelineItem>> onCreateDataSingle(boolean bypassCache) {
final IssueCommentService commentService =
ServiceFactory.get(IssueCommentService.class, bypassCache);

Single<List<TimelineItem>> commentSingle = ApiHelpers.PageIterator
Single<List<TimelineItem.TimelineComment>> commentSingle = ApiHelpers.PageIterator
.toSingle(page -> commentService.getIssueComments(mRepoOwner, mRepoName, issueNumber, page))
.compose(RxUtils.mapList(TimelineItem.TimelineComment::new));
Single<List<TimelineItem>> eventSingle = ApiHelpers.PageIterator
.compose(RxUtils.mapList(TimelineItem.TimelineComment::new))
.subscribeOn(Schedulers.io());
Single<List<TimelineItem.TimelineEvent>> eventSingle = ApiHelpers.PageIterator
.toSingle(page -> eventService.getIssueEvents(mRepoOwner, mRepoName, issueNumber, page))
.compose(RxUtils.filter(event -> INTERESTING_EVENTS.contains(event.event())))
.compose((RxUtils.mapList(TimelineItem.TimelineEvent::new)));
.compose((RxUtils.mapList(TimelineItem.TimelineEvent::new)))
.subscribeOn(Schedulers.io());

return Single.zip(commentSingle, eventSingle, (comments, events) -> {
ArrayList<TimelineItem> result = new ArrayList<>();
Expand Down

0 comments on commit 256692e

Please sign in to comment.