Skip to content

Conversation

sonalyadav1
Copy link
Contributor

Description (required)
Previously, super-popular items (e.g., Eiffel Tower) caused SPARQL query timeouts due to inefficient label and description fetching, resulting in grey pins and missing metadata in the app.

Fixes #6064

What changes did you make and why?

Optimized the SPARQL query for single entity metadata by using the wikibase:label service for efficient retrieval of labels and descriptions in the user's preferred language. Removed redundant label/description fetching logic to prevent Cartesian product and improve query performance, especially for super-popular items.

Tests performed (required)

Tested {build variant, ProdDebug} on {VIVO V25} with API level {35}.

1000115059

… service

- Use SERVICE wikibase:label for efficient retrieval of labels and descriptions in preferred language
- Remove redundant label/description fetching logic
- Prevent Cartesian product and improve query performance for
OPTIONAL {?item rdfs:label ?itemLabelAnyLanguage}
BIND(COALESCE(?itemLabelPreferredLanguage, ?itemLabelAnyLanguage, "?") as ?label)
# Get item label/class label/description in the preferred language of the user
SERVICE wikibase:label { bd:serviceParam wikibase:language "${LANG},en". }
Copy link
Member

@nicolas-raoul nicolas-raoul Jul 16, 2025

Choose a reason for hiding this comment

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

Let's say my phone is in French and I am visiting Japan.
So, ${LANG} is fr and most of the items around me only have labels in Japanese.
With this code, I do not see any label on most of the items, unfortunately (see screenshot).

A solution for this can be to append all possible Wikidata languages to that string. I will increase maintenance a bit as language codes are added/removed/modified from time to time, but that's a reasonable solution.

Screenshot_20250716-114221.png

@sonalyadav1
Copy link
Contributor Author

@nicolas-raoul I’ve added all assigned Wikidata languages to the label service for better coverage.

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.

I just added a nit comment, otherwise working great! :-)

@sonalyadav1
Copy link
Contributor Author

I just added a nit comment, otherwise working great! :-)

done!

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.

Fantastic, thanks! :-)

Copy link

✅ Generated APK variants!

@nicolas-raoul nicolas-raoul merged commit e5dbcfc into commons-app:main Jul 16, 2025
1 check passed
@nicolas-raoul
Copy link
Member

Since merging this, when uploading a picture near a QID, I get this:
Screenshot_20250716-175048~2.png

There should be a place name just before the interrogation point.

Maybe due to variable renaming? Not sure though.

The problem does not happen with the commit just before merging.

Would you mind checking? You can create a new issue.

@sonalyadav1
Copy link
Contributor Author

Would you mind checking? You can create a new issue.

Will check and create a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nearby for super-popular item: stays grey until "Could not load place data Unexpected response code"
2 participants