apps-android-commons icon indicating copy to clipboard operation
apps-android-commons copied to clipboard

[Bug]: Upload: the "Nearby place found" check sends the same Wikidata query once for every picture

Open Medhansh-741 opened this issue 1 week ago • 2 comments

Summary

When you upload pictures that have a location, the app asks Wikidata for places within 100 m of each picture, to show the "Nearby Place Found" popup. Pictures taken at the same spot get the same answer, but every picture still sends its own query, and they all go out at the same moment.

Each picture's page does its own check: https://github.com/commons-app/apps-android-commons/blob/c025f9e/app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaPresenter.kt#L131-L161 https://github.com/commons-app/apps-android-commons/blob/c025f9e/app/src/main/java/fr/free/nrw/commons/repository/UploadRepository.kt#L539-L559

The user's answer to the popup is already remembered per place (UploadActivity.nearbyPopupAnswers), but the lookup itself isn't.

#7421 is the same problem for the depiction search, and it leaves this check out on purpose. The two send the exact same query (same query file, 100 m), so right now every picture sends it twice. #7426 fixes the depiction half; this check would still send one per picture.

Steps to reproduce

  1. Pick 16 pictures taken at the same spot (mine are all within about 20 m of each other at Villa Borghese, Rome).
  2. Start the upload.
  3. Stay on the first screen while the pictures are processed.

Expected behaviour

Pictures taken at the same spot share one lookup.

Actual behaviour

On main (c025f9e), within about 1.6 seconds the app sent 32 queries with a 100 m radius: 16 from this check and 16 from the depiction search. They were only 3 different queries (the coordinates get rounded to 4 decimals), and all 32 went over the network. The answers came back 2 to 15 seconds later, and Wikidata answered one of them with 429 (rate limited).

To count them I used a test-only build that writes one line per lookup to a file. The phone drops app log lines when an app logs a lot ("LOGS OVER PROC QUOTA ... DROPPED"), so logcat alone undercounts.

I also added a test to UploadRepositoryUnitTest that calls checkNearbyPlaces for two pictures 3 m apart and expects one lookup. On main it fails:

TooManyActualInvocations: nearbyPlaces.getFromWikidataQuery(...)
Wanted 1 time:
But was 2 times

Device name

OnePlus CPH2491

Android version

Android 16

Commons app version

main at c025f9e (BetaDebug)

Device logs

From the test-only build's file. A depictionSearch / nearbyCheck line is written just before the query goes out, a send line when its answer comes back (q is a hash of the query text, so the same number means the same query). Times are relative to the first line in the file.

+34.786s depictionSearch radius 0.1
...  (16 of these, the last one:)
+35.252s depictionSearch radius 0.1
+36.166s nearbyCheck 41.91431,12.492299999999998
+36.179s nearbyCheck 41.91428,12.492299999999998
...  (16 of these, the last one:)
+36.370s nearbyCheck 41.914339999999996,12.492299999999998
+38.180s send radius 0.1 q1933272475 code 429 network true cache true
+38.302s send radius 0.1 q-999369191 code 200 network true cache true
...  (32 of these, the last one:)
+50.439s send radius 0.1 q-1680532006 code 200 network true cache true

Screenshots

Nothing to see on screen, the popup works. This is only about the requests.

Would you like to work on the issue?

Yes

@nicolas-raoul could you set the type for this one? I can't set it from my side.

Medhansh-741 avatar Nov 26 '26 00:11 Medhansh-741

Assigned to you, @Medhansh-741! Thanks!

nicolas-raoul avatar Nov 26 '26 01:11 nicolas-raoul

@nicolas-raoul opened #7437 for this. Pictures taken at the same spot now share one lookup, on the phone 16 pictures went from 16 lookups to 1.

Medhansh-741 avatar Nov 26 '26 01:11 Medhansh-741