Skip to content
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

Improve PRs/issues loading performance #1107

Merged
merged 5 commits into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions app/src/main/java/com/gh4a/ServiceFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.meisolsson.githubsdk.core.GitHubPaginationInterceptor;
import com.meisolsson.githubsdk.core.ServiceGenerator;
import com.meisolsson.githubsdk.core.StringResponseConverterFactory;
import com.meisolsson.githubsdk.service.checks.ChecksService;

import java.io.File;
import java.util.HashMap;
Expand Down Expand Up @@ -37,9 +36,6 @@ public class ServiceFactory {
private static final String DEFAULT_HEADER_ACCEPT =
"application/vnd.github.squirrel-girl-preview," // reactions API preview
+ "application/vnd.github.v3.full+json";
private static final String CHECKS_API_HEADER_ACCEPT =
"application/vnd.github.antiope-preview," // checks API preview
+ "application/vnd.github.v3.full+json";

private final static HttpLoggingInterceptor LOGGING_INTERCEPTOR = new HttpLoggingInterceptor()
.setLevel(HttpLoggingInterceptor.Level.BASIC);
Expand Down Expand Up @@ -173,8 +169,6 @@ private static <S> S createService(Class<S> serviceClass, final boolean bypassCa
final String header;
if (acceptHeader != null) {
header = acceptHeader;
} else if (serviceClass == ChecksService.class) {
header = CHECKS_API_HEADER_ACCEPT;
} else {
header = DEFAULT_HEADER_ACCEPT;
}
Expand Down
30 changes: 15 additions & 15 deletions app/src/main/java/com/gh4a/activities/PullRequestActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
import com.gh4a.fragment.CommitCompareFragment;
import com.gh4a.fragment.ConfirmationDialogFragment;
import com.gh4a.fragment.PullRequestFilesFragment;
import com.gh4a.fragment.PullRequestFragment;
import com.gh4a.fragment.PullRequestConversationFragment;
import com.gh4a.utils.ApiHelpers;
import com.gh4a.utils.IntentUtils;
import com.gh4a.utils.RxUtils;
Expand Down Expand Up @@ -118,7 +118,7 @@ public static Intent makeIntent(Context context, String repoOwner, String repoNa

private Issue mIssue;
private PullRequest mPullRequest;
private PullRequestFragment mPullRequestFragment;
private PullRequestConversationFragment mConversationFragment;
private IssueStateTrackingFloatingActionButton mEditFab;
private Review mPendingReview;
private boolean mPendingReviewLoaded;
Expand All @@ -129,8 +129,8 @@ public static Intent makeIntent(Context context, String repoOwner, String repoNa
private final ActivityResultLauncher<Intent> mCreateReviewLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
new ActivityResultHelpers.ActivityResultSuccessCallback(() -> {
if (mPullRequestFragment != null) {
mPullRequestFragment.reloadEvents(false);
if (mConversationFragment != null) {
mConversationFragment.reloadEvents(false);
}
loadPendingReview(true);
})
Expand Down Expand Up @@ -295,16 +295,16 @@ protected int[] getHeaderColorAttrs() {

@Override
protected Fragment makeFragment(int position) {
if (position == 1) {
if (position == PAGE_COMMITS) {
PullRequestMarker base = mPullRequest.base();
PullRequestMarker head = mPullRequest.head();
return CommitCompareFragment.newInstance(mRepoOwner, mRepoName, mPullRequestNumber,
base.label(), base.sha(), head.label(), head.sha());
} else if (position == 2) {
} else if (position == PAGE_FILES) {
return PullRequestFilesFragment.newInstance(mRepoOwner, mRepoName,
mPullRequestNumber, mPullRequest.head().sha());
} else {
Fragment f = PullRequestFragment.newInstance(mPullRequest,
Fragment f = PullRequestConversationFragment.newInstance(mPullRequest,
mIssue, mIsCollaborator, mInitialComment);
mInitialComment = null;
return f;
Expand All @@ -313,15 +313,15 @@ protected Fragment makeFragment(int position) {

@Override
protected void onFragmentInstantiated(Fragment f, int position) {
if (position == 0) {
mPullRequestFragment = (PullRequestFragment) f;
if (position == PAGE_CONVERSATION) {
mConversationFragment = (PullRequestConversationFragment) f;
}
}

@Override
protected void onFragmentDestroyed(Fragment f) {
if (f == mPullRequestFragment) {
mPullRequestFragment = null;
if (f == mConversationFragment) {
mConversationFragment = null;
}
}

Expand All @@ -337,8 +337,8 @@ protected Intent navigateUp() {

@Override
public void onCommentsUpdated() {
if (mPullRequestFragment != null) {
mPullRequestFragment.reloadEvents(true);
if (mConversationFragment != null) {
mConversationFragment.reloadEvents(true);
}
}

Expand Down Expand Up @@ -433,8 +433,8 @@ private void fillHeader() {
}

private void handlePullRequestUpdate() {
if (mPullRequestFragment != null) {
mPullRequestFragment.updateState(mPullRequest);
if (mConversationFragment != null) {
mConversationFragment.updateState(mPullRequest);
}
if (mIssue != null) {
Issue.Builder builder = mIssue.toBuilder().state(mPullRequest.state());
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,20 @@

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

public class PullRequestFragment extends IssueFragmentBase {
public class PullRequestConversationFragment extends IssueFragmentBase {
private static final int ID_LOADER_STATUS = 1;
private static final int ID_LOADER_HEAD_REF = 2;

private PullRequest mPullRequest;
private GitReference mHeadReference;
private boolean mHasLoadedHeadReference;

public static PullRequestFragment newInstance(PullRequest pr, Issue issue,
public static PullRequestConversationFragment newInstance(PullRequest pr, Issue issue,
boolean isCollaborator, IntentUtils.InitialCommentMarker initialComment) {
PullRequestFragment f = new PullRequestFragment();
PullRequestConversationFragment f = new PullRequestConversationFragment();

Repository repo = pr.base().repo();
Bundle args = buildArgs(repo.owner().login(), repo.name(),
Expand Down Expand Up @@ -313,10 +314,10 @@ protected Single<List<TimelineItem>> onCreateDataSingle(boolean bypassCache) {
});

return Single.zip(
issueCommentItemSingle,
eventItemSingle,
reviewTimelineSingle,
commitCommentWithoutReviewSingle,
issueCommentItemSingle.subscribeOn(Schedulers.io()),
eventItemSingle.subscribeOn(Schedulers.io()),
reviewTimelineSingle.subscribeOn(Schedulers.io()),
commitCommentWithoutReviewSingle.subscribeOn(Schedulers.io()),
(comments, events, reviewItems, commentsWithoutReview) -> {
ArrayList<TimelineItem> result = new ArrayList<>();
result.addAll(comments);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/gh4a/utils/RxUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static <T> SingleTransformer<T, T> mapFailureToValue(int code, T value) {
}

public static <T> Single<T> doInBackground(Single<T> upstream) {
return upstream.subscribeOn(Schedulers.newThread())
return upstream.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}

Expand Down