Place.java: change getWikiDataEntityID() method to increase speed

Before this commit, this method would perform the String replace method on the Wikidata link every time
getWikiDataEntityID() was called. Also, getWikiDataLink() was called. This caused poor performance
since both method calls are slow.

This commit changes the method to only run the slow methods if the entityID field is empty or
null. Once the field is populated, the method simply returns the field. This change allows
getWikiDataEntityID() to run much faster.
This commit is contained in:
Jason Whitmore 2025-02-09 18:25:19 -08:00
parent 34943542bf
commit 950df4e61b

View file

@ -232,13 +232,23 @@ public class Place implements Parcelable {
*/ */
@Nullable @Nullable
public String getWikiDataEntityId() { public String getWikiDataEntityId() {
if (this.entityID != null && !this.entityID.equals("")) {
return this.entityID;
}
if (!hasWikidataLink()) { if (!hasWikidataLink()) {
Timber.d("Wikidata entity ID is null for place with sitelink %s", siteLinks.toString()); Timber.d("Wikidata entity ID is null for place with sitelink %s", siteLinks.toString());
return null; return null;
} }
//Determine entityID from link
String wikiDataLink = siteLinks.getWikidataLink().toString(); String wikiDataLink = siteLinks.getWikidataLink().toString();
return wikiDataLink.replace("http://www.wikidata.org/entity/", "");
if (wikiDataLink.contains("http://www.wikidata.org/entity/")) {
this.entityID = wikiDataLink.substring("http://www.wikidata.org/entity/".length());
return this.entityID;
}
return null;
} }
/** /**