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

Fix TransactionTooLargeException when opening HistoryDetailActivity #16105

Merged
merged 12 commits into from
Mar 17, 2022

Conversation

RenanLukas
Copy link
Contributor

Fixes #16012

Depends on: wordpress-mobile/WordPress-FluxC-Android#2310

To test:
1 - Log in
2 - Select a site
3 - On "My Site", tap on "Posts"
4 - Tap on a post that was updated at least once
5 - Tap on overflow menu (three vertical dots on top right)
6 - Tap on "History"
7 - Tap on any Revision on list. Revision details screen should open, instead of the app crashing.

Regression Notes

  1. Potential unintended areas of impact
    Revision details ViewPager (introduced a bug while developing and then fixed it)

  2. What I did to test those areas of impact (or what existing automated tests I relied on)
    Manual testing opening history details screen with different sites, moving the ViewPager from beginning to end.

  3. What automated tests I added (or what prevented me from doing so)
    I've tried to update HistoryViewModelTest with my changes, but couldn't do it because OnRevisionsFetched visibility is limited. If there are any ideas to have this code tested the way it is, please let me know.

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

…n IDs to avoid TransactionTooLargeException (the new parameters are used to fetch the revisions)
@RenanLukas RenanLukas added this to the 19.5 milestone Mar 14, 2022
@RenanLukas RenanLukas requested review from khaykov and develric March 14, 2022 19:20
@peril-wordpress-mobile
Copy link

peril-wordpress-mobile bot commented Mar 14, 2022

You can trigger optional UI/connected tests for these changes by visiting CircleCI here.

@RenanLukas
Copy link
Contributor Author

👀 CI

@peril-wordpress-mobile
Copy link

peril-wordpress-mobile bot commented Mar 14, 2022

You can test the changes on this Pull Request by downloading the APKs:

Copy link
Member

@khaykov khaykov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling this one, @renanferrari 🙇 It works well! I left couple of comments in the code.


ActivityLauncher.viewHistoryDetailForResult(this, mRevision, revisions);
private long[] getRevisionsIds(@NonNull final List<Revision> revisions) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand this correctly, number of returned ID's will be same as the number of revisions, so maybe we don't need to extract them into idsList first?

Can we simplify it into something like this (not tested)?:

  private long[] getRevisionsIds(@NonNull final List<Revision> revisions) {
        final long[] idsArray = new long[revisions.size()];
        for (int i = 0; i < revisions.size(); i++) {
            final Revision current = revisions.get(i);
            idsArray[i] = current.getRevisionId();
        }
        return idsArray;
    }

final ArrayList<Revision> revisions = new ArrayList<>();
for (int i = 0; i < revisionModels.size(); i++) {
final RevisionModel current = revisionModels.get(i);
final Revision revision = new Revision(current.getRevisionId(), current.getDiffFromVersion(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revision has constructor that takes a RevisionModel. Wonder if we can utilize it?


private fun removeRevisionsFromLocalDB(post: PostModel, revisions: List<RevisionModel>) {
revisions.forEach {
postStore.deleteLocalRevision(it, site, post)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we only remove the revisions received from the endpoint, there is a chance we might have some revisions not removed, if for some reason they are not in the response. What do you think about removing all the revision for specific post?

final long[] previousRevisionsIds = getArguments().getLongArray(EXTRA_PREVIOUS_REVISIONS_IDS);
final List<RevisionModel> revisionModels = new ArrayList<>();
for (final long revisionId : previousRevisionsIds) {
revisionModels.add(mPostStore.getRevisionById(revisionId));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably not a significant issue, but I wonder if performance might suffer when accessing DB from main thread for a post wit a lot of changes.

@RenanLukas
Copy link
Contributor Author

Thanks for the review @khaykov ! I've addressed the issues we discussed 👍 (except this one - if you think it's worth, I'll create a separate issue for it and will work on it in the future)

Copy link
Member

@khaykov khaykov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thank you! lgtm 🚀

@RenanLukas RenanLukas merged commit 0bfd28d into trunk Mar 17, 2022
@RenanLukas RenanLukas deleted the issue/16012-exception-opening-post-revisions branch March 17, 2022 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RuntimeException: Failure from system
2 participants