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

With lazy loading of contributions #3566

Merged
merged 48 commits into from
May 28, 2020

Conversation

maskaravivek
Copy link
Member

@maskaravivek maskaravivek commented Mar 23, 2020

Fixes #2904
Fixes #1993
Fixes #3667
Fixes #52

Copy link

@tests-checker tests-checker bot left a comment

Choose a reason for hiding this comment

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

Could you please add tests to make sure this change works as expected?

@codecov-io
Copy link

codecov-io commented Mar 23, 2020

Codecov Report

Merging #3566 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##             master   #3566   +/-   ##
========================================
  Coverage      7.82%   7.82%           
  Complexity      347     347           
========================================
  Files           294     294           
  Lines         12675   12675           
  Branches       1015    1015           
========================================
  Hits            992     992           
  Misses        11611   11611           
  Partials         72      72           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bb4f91c...bb4f91c. Read the comment docs.

* With lazy loading of contributions

* With contribution fetch

* fix display of contributions

* BugFixes Lazy Load Contributions
* Use PageId as primary Key
* show progress in CLF only whenn contributions are empty (graceful pagination)
* Migration 1_2

Co-authored-by: Vivek Maskara <maskaravivek@gmail.com>
@maskaravivek maskaravivek marked this pull request as ready for review April 21, 2020 23:05
@macgills
Copy link
Collaborator

I am seeing a few of these logs

2020-05-20 13:23:45.171 13978-14916/fr.free.nrw.commons.beta E/ContributionBoundaryCallback$fetchContributions: Failed to fetch contributions: Query map was null (parameter #3)
        for method MediaInterface.getMediaListForUser

should we be null checking

continuationStore.put(key, mwQueryResponse.continuation());

I haven't looked much at the structure of the returned response and what precisely a continuation is

@maskaravivek
Copy link
Member Author

maskaravivek commented May 20, 2020

@macgills Thanks for testing the PR again. I have fixed the issue and have also addressed other code review comments.

Query map was null

Earlier, the end of the list was not handled so this error was coming.

@@ -123,7 +140,12 @@ public MediaClient(MediaInterface mediaInterface, MediaDetailInterface mediaDeta
|| null == mwQueryResponse.query().pages()) {
return Observable.empty();
}
continuationStore.put(key, mwQueryResponse.continuation());
if(mwQueryResponse.continuation() != null) {
continuationStore.put(key, mwQueryResponse.continuation());
Copy link
Collaborator

Choose a reason for hiding this comment

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

if null couldn't we just remove the key and then it all works as usual without the extra map

Copy link
Member Author

Choose a reason for hiding this comment

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

If we remove the key then it would be like fetching the first page. The API call would be made without the continuation params.

Copy link
Collaborator

Choose a reason for hiding this comment

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

And then the Db update would return the same data, not retriggering a boundaryCallback as the list would be unchanged, I think.

Though I guess now the api is set up with a continuation... I am quite unsure of how to proceed

Copy link
Collaborator

Choose a reason for hiding this comment

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

and the continuation map is never assigned but I am sure you are on that

Copy link
Member Author

Choose a reason for hiding this comment

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

Though I guess now the api is set up with a continuation... I am quite unsure of how to proceed

Yeah, right. As the API is set up with a continuation it will start fetching all the pages again. On a related note, the current logic of fetching pages(that I added in this PR) is very naive and can be improved. For now, i wanted to keep things simple.

and the continuation map is never assigned but I am sure you are on that

I didn't understand this comment.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I should have said continuationExists map but it is resolved now.

This is a bit "upending the teatable" but it seems to me that this endpoint shouldn't use continuation at all, we could happily query using

image

but perhaps that is best suited for another ticket

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah we can use aistart and aiend parameter to fetch contributions based on timestamp but I don't think that can replace continuation. With start and end timestamp, there's no way to be sure how many contributions would be returned. For eg. recently I uploaded around 2000 images in a day. The API would then return all images in one call. It would defeat the purpose of pagination.

To limit it to 10 images per call we will have to use ailimit and then continuation will still come into picture.

Copy link
Member Author

Choose a reason for hiding this comment

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

@macgills Is everything working in this PR now? It would be great if you could do another test.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is a little trickier granted but if at top of list we request media since now and reorder it so it is oldest first it hoovers along nicely.

Bottom of the list request since last item timestamp + newest first.

Again perhaps a discussion for another ticket. I will get to testing shortly

@codecov-commenter
Copy link

codecov-commenter commented May 21, 2020

Codecov Report

Merging #3566 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##             master   #3566   +/-   ##
========================================
  Coverage      7.81%   7.81%           
  Complexity      334     334           
========================================
  Files           295     295           
  Lines         12352   12352           
  Branches        992     992           
========================================
  Hits            965     965           
  Misses        11319   11319           
  Partials         68      68           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5f12c5f...5f12c5f. Read the comment docs.

@macgills
Copy link
Collaborator

The ux after uploading is not as good, you have to scroll up to see the in progress upload and then when it is done the list jumps down to the next item and you have to scroll up again to see the now uploaded item. Maybe if the deleting and saving of the inProgress/complete Contribution were in a transaction it would look better.

@maskaravivek
Copy link
Member Author

@macgills I have fixed the UI issues. I have made the following changes:

  • am deleting and saving in a single transaction
  • have replaced a couple of usages of save with update
  • started persisting time information in dateUploaded column of Contribution DB. Earlier just date was persisted so all contributions uploaded on a particular day had the same timestamp.

@macgills
Copy link
Collaborator

macgills commented May 26, 2020

The UI is better but we still don't scroll to the new uploading item however all things considered I think that is an acceptable concession.

I am happy with this PR once ioThreadScheduler.scheduleDirect is replaced with completeables that are added to a compositeDisposable so they can be gracefully cancelled.

May be for the best to return these from the dao eg

@Insert
public void saveSynchronous()
@Delete
public void deleteSynchronous()
@Transaction
public void saveAndDeleteSynchronous(){
deleteSynchronous()
saveSynchronous()
}

public Completeable saveAndDelete(){
return Completeable.fromAction{
saveAndDeleteSynchronous()
}
}

@maskaravivek
Copy link
Member Author

Thanks for testing the PR @macgills.

I have updated the PR.

@macgills
Copy link
Collaborator

@neslihanturan could you give this a quick test? I think you have a far greater number of contributions than I do.

Otherwise looks good, has my approval

Copy link
Collaborator

@ashishkumar468 ashishkumar468 left a comment

Choose a reason for hiding this comment

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

LGTM

@neslihanturan
Copy link
Collaborator

Scrolling is a lot smoother, my first insights about this Pr is very positive. Can you emphasize if there is a function that must be tested.

@macgills
Copy link
Collaborator

@neslihanturan I just wanted verification a large data set is performant, that is good enough for my curiosity

Copy link
Collaborator

@neslihanturan neslihanturan left a comment

Choose a reason for hiding this comment

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

Thanks a lot @maskaravivek , this PR make the user feel the improvement.

@neslihanturan neslihanturan merged commit d863a40 into commons-app:master May 28, 2020
ashishkumar468 pushed a commit to ashishkumar468/apps-android-commons that referenced this pull request Oct 10, 2020
ashishkumar468 pushed a commit to ashishkumar468/apps-android-commons that referenced this pull request Oct 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants