-
Notifications
You must be signed in to change notification settings - Fork 47
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
Paginate scrolling in test result screen #511
Conversation
app/src/main/java/org/openobservatory/ooniprobe/adapters/ResultListAdapter.java
Outdated
Show resolved
Hide resolved
.limit(20) | ||
.offset(pageNumber * 20) | ||
.orderBy(Result_Table.start_time, false) | ||
.queryList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If while you have fetched the first page of data, another result is written to the results table (because there is a test currently running), fetching the next page will be off by one.
You could instead use the result_id
as a pagination handler and query WHERE result_id < $last_result_id
to get the next page worth of data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The query mechanism has been updated to use result_id
based pagination
# Conflicts: #app/src/main/java/org/openobservatory/ooniprobe/receiver/TestRunBroadRequestReceiver.java
|
||
Integer prevKey; | ||
try { | ||
prevKey = (!response.isEmpty()) ? Objects.requireNonNull(Iterables.getFirst(response, null)).id - 20 : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you actually need the previous key? In which circumstances are you using this?
I don't think you can derive this by just subtracting 20, because some test results may have been removed and so the list of IDs may have "holes" in it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need the previous key to return it and allow navigation, IIUC the code.
I don't know how the code behaves when there are holes. It may be that, while you are scrolling back, the Android code will continue to query until it has enough elements to fill the screen, so it may be that we don't need to be more precise at the cost of executing more queries.
I think @aanorbel should clarify this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To optimize the load time and memory usage, the records loaded will not always stay in memory, so the previous key is used when the records previously loaded are no longet in memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mainly comments related to how querying the database works
} | ||
// This API defines that it's out of data when a page returns empty. When out of | ||
// data, we return `null` to signify no more pages should be loaded | ||
Integer nextKey = (!response.isEmpty()) ? Iterables.getLast(response).id : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Integer nextKey = (!response.isEmpty()) ? Iterables.getLast(response).id : null; | |
Integer nextKey = (!response.isEmpty()) ? Iterables.getLast(response).id + 1 : null; |
Conceptually, the next page seems to start at index $last + 1
rather than at index $last
. That said, I can see how smooth scrolling means that probably we want to keep the last element in scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The operand used for the query is lessThan
so using Iterables.getLast(response).id + 1
will mean we lose a record.
app/src/main/java/org/openobservatory/ooniprobe/domain/QueryDataSource.java
Outdated
Show resolved
Hide resolved
|
||
Integer prevKey; | ||
try { | ||
prevKey = (!response.isEmpty()) ? Objects.requireNonNull(Iterables.getFirst(response, null)).id - 20 : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need the previous key to return it and allow navigation, IIUC the code.
I don't know how the code behaves when there are holes. It may be that, while you are scrolling back, the Android code will continue to query until it has enough elements to fill the screen, so it may be that we don't need to be more precise at the cost of executing more queries.
I think @aanorbel should clarify this.
Co-authored-by: Simone Basso <[email protected]>
…taSource.java Co-authored-by: Simone Basso <[email protected]>
The scroll back will need to use the |
…droid into issues/1430
…droid into issues/1430
Stale |
Fixes ooni/probe#1430
Proposed Changes
HeterogeneousRecyclerAdapter
Sample Pager logs