From a9c4b0af16ac702c30ddfb229c16b2bb1722d80f Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Wed, 8 Mar 2017 07:45:11 +0000 Subject: [PATCH] Cache String, not URL, in ColumnAdditionByFetchingURLsOperation --- ...ColumnAdditionByFetchingURLsOperation.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/main/src/com/google/refine/operations/column/ColumnAdditionByFetchingURLsOperation.java b/main/src/com/google/refine/operations/column/ColumnAdditionByFetchingURLsOperation.java index ebcb4fcbd..d29b85d52 100644 --- a/main/src/com/google/refine/operations/column/ColumnAdditionByFetchingURLsOperation.java +++ b/main/src/com/google/refine/operations/column/ColumnAdditionByFetchingURLsOperation.java @@ -172,7 +172,7 @@ public class ColumnAdditionByFetchingURLsOperation extends EngineDependentOperat final protected Evaluable _eval; final protected long _historyEntryID; protected int _cellIndex; - protected Map _urlCache; + protected Map _urlCache; public ColumnAdditionByFetchingURLsProcess( Project project, @@ -185,7 +185,7 @@ public class ColumnAdditionByFetchingURLsOperation extends EngineDependentOperat _engine = engine; _eval = eval; _historyEntryID = HistoryEntry.allocateID(); - _urlCache = new HashMap(); + _urlCache = new HashMap(); } @Override @@ -259,18 +259,12 @@ public class ColumnAdditionByFetchingURLsOperation extends EngineDependentOperat CellAtRow cachedFetch(CellAtRow urlData) { String urlString = urlData.cell.value.toString(); - URL url = null; - try { - url = new URL(urlString); - } catch (MalformedURLException e) { - return null; - } - Serializable cellResult = _urlCache.get(url); + Serializable cellResult = _urlCache.get(urlString); if (cellResult == null) { - cellResult = fetch(url); + cellResult = fetch(urlString); if (cellResult != null) { - _urlCache.put(url, cellResult); + _urlCache.put(urlString, cellResult); } try { @@ -295,7 +289,14 @@ public class ColumnAdditionByFetchingURLsOperation extends EngineDependentOperat return null; } - Serializable fetch(URL url) { + Serializable fetch(String urlString) { + URL url = null; + try { + url = new URL(urlString); + } catch (MalformedURLException e) { + return null; + } + try { URLConnection urlConnection = url.openConnection(); // urlConnection.setRequestProperty(_headerKey, _headerValue);