mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
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:
parent
34943542bf
commit
950df4e61b
1 changed files with 11 additions and 1 deletions
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue