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

Made Split to Nearby Query into a fast query for coordinates + a details query for each pin #5731

Merged
merged 47 commits into from
Aug 4, 2024

Conversation

kanahia1
Copy link
Contributor

@kanahia1 kanahia1 commented May 14, 2024

Description (required)

Fixes #4560

What changes did you make and why?

Tests performed (required)

Tested prodDebug on Samsung S21 FE with API level 33.

Screenshots (for UI changes only)

WhatsApp.Video.2024-05-14.at.20.36.17_5a90b1f7.mp4

@nicolas-raoul
Copy link
Member

Testing now.

Just wondering: Is there a specific reason why your branch is called kanahia1-main?
It is usually good to have a branch name that reflects the issue ID and an extremely short summary of the issue.
It makes it easier to work on different things in parallel. :-)

@kanahia1
Copy link
Contributor Author

There's no specific reason for it 😄 From next time I will try to follow proper naming.

Copy link
Member

@nicolas-raoul nicolas-raoul left a comment

Choose a reason for hiding this comment

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

Would you mind implementing a loop that asynchrously loads each item's details, for all shown points? Depending on the user's settings it will make many points disappear, which is not ideal user experience but it is the best we can do while having fast nearby maps in areas with many items.

Thanks! 🙂

@kanahia1
Copy link
Contributor Author

Sure, I will do asynchronous loop to load pin's details

@kanahia1
Copy link
Contributor Author

Hey @nicolas-raoul, I'm bit confused here.

Should the queries look like given below?

  1. Run query for loading only pins (coordinates)
  2. Run query to load all the data about all the pins async, which may also remove the pins from screen (This query will be similar to what we have already)
  3. In case, user clicked over the pin and data has not been loaded (from 2.) then run query to load data for that particular pin as it is much faster.

@nicolas-raoul
Copy link
Member

Sounds good! :-)

For the second query, you can specify the QIDs of the pins, that will make the query much faster.
Here is a example of how to specify QIDs: https://www.wikidata.org/wiki/User:Vojt%C4%9Bch_Dost%C3%A1l/app-Czech_uploads
I believe this is the relevant documentation: https://www.w3.org/TR/sparql11-query/#inline-data
Obviously, the second query does not need to care about coordinates.
Let me know if anything is unclear. :-)

@nicolas-raoul
Copy link
Member

By the way, I believe it would be user-friendly to first show pins in grey color to mean "unfiltered". Then upon receiving the result from the second request, hide the pins that do not match the filter, and set the normal color to the pins that match the filter. What do you think? 🙂

@kanahia1
Copy link
Contributor Author

Yeah, That would be great!

@kanahia1
Copy link
Contributor Author

Hello @nicolas-raoul, I have improvised query as per suggestions by you and it's working fine for the smaller regions

WhatsApp.Video.2024-05-16.at.15.15.29_37c183a9.mp4

But I have faced an issue because we are using List of QID (which becomes really large for city like capital of India) the server returns error 414 which is because our url length exceeds a limit (which is because of the large query)

WhatsApp.Video.2024-05-16.at.15.16.45_392342b7.mp4

How about replacing the List of QID with similar method we had earlier?

@nicolas-raoul
Copy link
Member

Would you mind splitting the second query into several queries of 50 QIDs max, and using the results as they come? Ideally sort them by their distance to the center of the search rectangle, then run the queries starting from the nearest 50 QIDs.

Sorry to add something again, but when a not-yet-loaded QID is tapped by the user, it would be great to run the second query for that point, in parallel with the above, it will probably return the result fast and the user will see the label/class/filter status/etc without having to wait for all points to load.

@kanahia1
Copy link
Contributor Author

Thank you for suggestion and I feel it will make queries even better.

And I have added that when pins are not loaded still the user can get the details for a pin.

Screen_Recording_20240516_164159_Commons.mp4

@kanahia1
Copy link
Contributor Author

kanahia1 commented May 17, 2024

Hello Nicolas, I have divided the second query into batches fixing the issue we were facing due to large size of second query. Now the first query has became more effective.

VID-20240517-WA0007.mp4

Copy link
Member

@nicolas-raoul nicolas-raoul left a comment

Choose a reason for hiding this comment

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

It is getting better and better, keep up the great work :-)
Brilliant work on the SPARQL query especially!

@kanahia1
Copy link
Contributor Author

Hello Nicolas, Thanks for the suggestions and now loading of pins has became even more efficient.

WhatsApp.Video.2024-05-18.at.11.13.21_560bd12d.mp4

@nicolas-raoul
Copy link
Member

Looks fantastic! I will try it as soon as I get home. 🙂

@kanahia1
Copy link
Contributor Author

Hi @nicolas-raoul, on digging I am able to find that issue was caused by ongoing network call which was not stopped on starting new call. Now I have updated the code, I hope it should fix up the issue.

WhatsApp.Video.2024-05-19.at.10.03.18_d70e1a6f.mp4

@nicolas-raoul
Copy link
Member

I am experiencing several unexpected things, especially when swgitching to other apps or when the screen goes black:

screen-20240519-213301.mp4

Also, maybe modifying the default zoom level would be good (zoomed more, mening it loads less items by default).

@kanahia1
Copy link
Contributor Author

Sure, I will update the zoom level ;-)

I tried switching apps. It moves the map to the default location

VID-20240519-WA0003.mp4

Actually It wasn't clear from the video provided. On switching apps the map return to the my location (in my case)

@nicolas-raoul
Copy link
Member

Let's say the map is fully loaded, including points details (exist or not, etc). Then when I turn the screen off and on again, all points on the map turned back to grey again, and it starts sending requests again 3-by-3. It should not reload unless it is kicked ou of memory (this happens on a device with lots of memory and no other running app so memory is not the issue).
I send a screencast on Zulip.

@kanahia1
Copy link
Contributor Author

Hey Nicolas, I have fixed the unnecessary reloads caused onResume.

WhatsApp.Video.2024-05-29.at.12.21.09_a7068d1b.mp4

We may also need to implement method to load pending pins which are not loaded on changing the apps as it returns <-- HTTP FAILED: java.io.InterruptedIOException, I am working over it and will also share a commit for it ASAP

@kanahia1
Copy link
Contributor Author

Hi @nicolas-raoul, I have fixed the bug in 2251c62

WhatsApp.Video.2024-07-10.at.18.31.15_d1eac0ec.mp4


private List<Place> updatedPlaceList;
private LatLng updatedLatLng;
private boolean searchble;
Copy link
Member

Choose a reason for hiding this comment

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

typo?

locationPermissionGranted();
if (lastFocusLocation == null && lastKnownLocation == null) {
locationPermissionGranted();
}else if (updatedPlaceList != null){
Copy link
Member

Choose a reason for hiding this comment

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

minor: space between } and else

});
}

private void savePlaceToDB(Place place) {
Copy link
Member

Choose a reason for hiding this comment

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

javadoc.
In Java we ususally use full words: savePlaceToDatabase

Copy link
Member

@nicolas-raoul nicolas-raoul left a comment

Choose a reason for hiding this comment

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

When I load Nearby for the first time, it loads a much wider rectangle than what is seen on screen.
Then when I move the map and let the pins refresh, that time only pins visible on screen are loaded.

Any idea what makes it load too many pins the first time? It makes the initial query longer and makes many unneeded queries to the server.

@kanahia1
Copy link
Contributor Author

kanahia1 commented Jul 28, 2024

When I load Nearby for the first time, it loads a much wider rectangle than what is seen on screen. Then when I move the map and let the pins refresh, that time only pins visible on screen are loaded.

Any idea what makes it load too many pins the first time? It makes the initial query longer and makes many unneeded queries to the server.

Fixed this issue in 6fed9f4

@kanahia1
Copy link
Contributor Author

Hello @nicolas-raoul, I have added jcenter in 4f7cbfc which seems to be fix for https://github.com/commons-app/apps-android-commons/actions/runs/10131832421/job/28015018616?pr=5731

Could not resolve all files for configuration ':app:betaDebugCompileClasspath'.
Could not find com.dinuscxj:circleprogressbar:1.1.1.

as this library is hosted on jcenter https://mvnrepository.com/artifact/com.dinuscxj/circleprogressbar?repo=jcenter

@nicolas-raoul
Copy link
Member

Maybe not a big issue, but I see the pin at the top appearing and disappearing:

PXL_20240730_012259644.mp4

sorry for the bad video quality

@kanahia1
Copy link
Contributor Author

Maybe not a big issue, but I see the pin at the top appearing and disappearing:

PXL_20240730_012259644.mp4
sorry for the bad video quality

If possible can you please share the location over zulip (for testing)

Copy link
Member

@nicolas-raoul nicolas-raoul left a comment

Choose a reason for hiding this comment

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

Good job, you are quickly approaching mergeability for this pull request :-)

@@ -204,6 +206,7 @@ public static class Table {
static final String COLUMN_COMMONS_LINK = "location_commons_link";
static final String COLUMN_PIC = "location_pic";
static final String COLUMN_EXISTS = "location_exists";
static final String COLUMN_ENTITY_ID = "location_entity_id";
Copy link
Member

Choose a reason for hiding this comment

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

Could you please add a comment explaining why this line is needed? And whether it can be empty, and an example value. Thanks!

private PlaceAdapter adapter;
private GeoPoint lastMapFocus;
private NearbyParentFragmentInstanceReadyCallback nearbyParentFragmentInstanceReadyCallback;
private boolean isAdvancedQueryFragmentVisible = false;
private Place nearestPlace;
private volatile boolean stopQuery;

private List<Place> updatedPlaceList;
Copy link
Member

Choose a reason for hiding this comment

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

updatedPlaceList -> updatedPlacesList

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for reviewing, I have made all suggested changes in the newer commit.

@nicolas-raoul
Copy link
Member

I tested more there are still a few bugs but soon mergeable I think. 🙂

The biggest problem: It seems like the first time (for instance after installing the app) Nearby pins do not load, until I switch to home activity then come back:

screen-20240803-222510.mp4

@kanahia1
Copy link
Contributor Author

kanahia1 commented Aug 3, 2024

I have shared a newer commit fixing this bug. Can you please test it.

WhatsApp.Video.2024-08-03.at.21.09.22_36e5bf8f.mp4

@nicolas-raoul
Copy link
Member

Fantastic, thanks Kanahia for this pull request, it is a great improvement!
I will merge for now, and submit anything else as new GitHub issues. 🙂

@nicolas-raoul nicolas-raoul merged commit 2d63f35 into commons-app:main Aug 4, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants