Bug 1265708 - Post: query topsites metadata by URL without ref too r=sebastian a=sylvestre FIREFOX_48_0b5_BUILD1 FIREFOX_48_0b5_RELEASE
authorAndrzej Hunt <ahunt@mozilla.com>
Fri, 03 Jun 2016 14:05:42 -0700
changeset 383734 dd7af1fa4ece1cb3158d08c80dfcbf1c6ca830fb
parent 383733 a46e0c70d190431821b11d8968d07648fec5d1c7
child 383735 771ddc92f65c3fa61c74f40539a4135559771b83
push id22092
push userbmo:dburns@mozilla.com
push dateMon, 04 Jul 2016 23:04:12 +0000
reviewerssebastian, sylvestre
bugs1265708
milestone48.0
Bug 1265708 - Post: query topsites metadata by URL without ref too r=sebastian a=sylvestre MozReview-Commit-ID: KzbKJjRm4Za
mobile/android/base/java/org/mozilla/gecko/home/TopSitesPanel.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/TopSitesPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/TopSitesPanel.java
@@ -12,18 +12,16 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import org.mozilla.gecko.GeckoProfile;
 import org.mozilla.gecko.R;
-import org.mozilla.gecko.Tab;
-import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.db.BrowserContract.Thumbnails;
 import org.mozilla.gecko.db.BrowserContract.TopSites;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.favicons.Favicons;
 import org.mozilla.gecko.favicons.OnFaviconLoadedListener;
 import org.mozilla.gecko.gfx.BitmapUtils;
@@ -810,31 +808,41 @@ public class TopSitesPanel extends HomeF
 
         @Override
         public Map<String, ThumbnailInfo> loadInBackground() {
             final Map<String, ThumbnailInfo> thumbnails = new HashMap<String, ThumbnailInfo>();
             if (mUrls == null || mUrls.size() == 0) {
                 return thumbnails;
             }
 
+            // We need to query metadata based on the URL without any refs, hence we create a new
+            // mapping and list of these URLs (we need to preserve the original URL for display purposes)
+            final Map<String, String> queryURLs = new HashMap<>();
+            for (final String pageURL : mUrls) {
+                queryURLs.put(pageURL, StringUtils.stripRef(pageURL));
+            }
+
             // Query the DB for tile images.
             final ContentResolver cr = getContext().getContentResolver();
-            final Map<String, Map<String, Object>> metadata = mDB.getURLMetadata().getForURLs(cr, mUrls, COLUMNS);
+            // Use the stripped URLs for querying the DB
+            final Map<String, Map<String, Object>> metadata = mDB.getURLMetadata().getForURLs(cr, queryURLs.values(), COLUMNS);
 
             // Keep a list of urls that don't have tiles images. We'll use thumbnails for them instead.
             final List<String> thumbnailUrls = new ArrayList<String>();
-            for (String url : mUrls) {
-                ThumbnailInfo info = ThumbnailInfo.fromMetadata(metadata.get(url));
+            for (final String pageURL : mUrls) {
+                final String queryURL = queryURLs.get(pageURL);
+
+                ThumbnailInfo info = ThumbnailInfo.fromMetadata(metadata.get(queryURL));
                 if (info == null) {
                     // If we didn't find metadata, we'll look for a thumbnail for this url.
-                    thumbnailUrls.add(url);
+                    thumbnailUrls.add(pageURL);
                     continue;
                 }
 
-                thumbnails.put(url, info);
+                thumbnails.put(pageURL, info);
             }
 
             if (thumbnailUrls.size() == 0) {
                 return thumbnails;
             }
 
             // Query the DB for tile thumbnails.
             final Cursor cursor = mDB.getThumbnailsForUrls(cr, thumbnailUrls);