From 950df4e61b32367b5c87c07a1f0e856bd1b47651 Mon Sep 17 00:00:00 2001 From: Jason Whitmore Date: Sun, 9 Feb 2025 18:25:19 -0800 Subject: [PATCH] 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. --- .../main/java/fr/free/nrw/commons/nearby/Place.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/Place.java b/app/src/main/java/fr/free/nrw/commons/nearby/Place.java index 21dd14131..3b3b798eb 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/Place.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/Place.java @@ -232,13 +232,23 @@ public class Place implements Parcelable { */ @Nullable public String getWikiDataEntityId() { + if (this.entityID != null && !this.entityID.equals("")) { + return this.entityID; + } + if (!hasWikidataLink()) { Timber.d("Wikidata entity ID is null for place with sitelink %s", siteLinks.toString()); return null; } + //Determine entityID from link 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; } /**